Milk Scheduling
InterviewTime limit1sMemory limit128 MB
Schedule at most one cow per time unit before its deadline to maximize total gallons of milk.
Problem
Farmer John has cows that need to be milked. Milking one cow takes exactly one unit of time.
The cows are impatient, so a cow refuses to be milked if Farmer John waits too long. Cow gives gallons of milk, but only if she is milked before her deadline at time . Time starts at , so at most cows in total can be milked before time . In other words, a cow with deadline has to take one of the first slots.
Find the largest amount of milk Farmer John can get if he milks the cows in the best possible order.
Input
The first line contains the number of cows . ()
Each of the next lines contains two integers separated by a space: the gallons and the deadline of cow . (, )
Output
Print the maximum number of gallons of milk Farmer John can obtain, on one line.