luogu#P4952. [USACO04MAR] Financial Aid
[USACO04MAR] Financial Aid
Problem Description
Humans can choose from many colleges, but cows have nowhere to go to school. To solve this problem, Bessie and her friends founded a cow university called Moo Moo University.
In order to select outstanding students, they invented a Cow Scholastic Ability Test (CSAT). The scores of this test are extremely precise: each cow’s score can be represented by an integer between and , and it is guaranteed that no two cows have the same score.
Tuition at Moo Moo University is very expensive, and the cows cannot afford it, so they each apply for financial aid. The government does not provide scholarships for cows; all funding must be paid from the school’s limited financial aid fund (let the total fund be ).
Moo Moo University has dorm rooms. Since is an odd number, Bessie can accept applications from only cows, and she swears she will not admit fewer than cows. In addition, she wants the freshmen to have excellent CSAT performance, and she measures the overall level by the median. The median is the score in the exact middle after sorting. For example, the median of 3, 8, 9, 7, 5 is 7.
This year, a total of cows apply. Given each cow’s CSAT score and the amount of financial aid requested, as well as the total amount the school can sponsor, determine which cows Bessie should accept so that the median score is as large as possible.
Input Format
Line 1: Three integers separated by spaces: , , and . , , .
Lines 2 to : Each line contains two integers separated by a space. The first number is the cow’s CSAT score, and the second number is the amount of financial aid this cow requires, . .
Output Format
Line 1: One integer, the maximum median Bessie can achieve. If the current fund is not enough to support any cows, output .
3 5 70
30 25
50 21
20 20
5 18
35 30
35
Hint
Bessie accepts cows with CSAT scores 5, 35, and 50. The median is 35, and the total financial aid required is .
Translated by ChatGPT 5