#P3093. [USACO13DEC] Milk Scheduling S

[USACO13DEC] Milk Scheduling S

Description

Farmer John has NN cows that need to be milked (1N10,0001 \le N \le 10,000), each of which takes only one unit of time to milk.

Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow ii produces gig_i gallons of milk (1gi10001 \le g_i \le 1000), but only if she is milked before a deadline at time did_i (1di10,0001 \le d_i \le 10,000). Time starts at t=0t=0, so at most xx total cows can be milked prior to a deadline at time t=xt=x.

Please help Farmer John determine the maximum amount of milk that he can obtain if he milks the cows optimally.

Input Format

  • Line 11: The value of NN.

  • Lines 21+N2\dots 1+N: Line i+1i+1 contains the integers gig_i and did_i.

Output Format

  • Line 11: The maximum number of gallons of milk Farmer John can obtain.
4 
10 3 
7 5 
8 1 
2 1 

25 

Hint

There are 44 cows. The first produces 1010 gallons of milk if milked by time 33, and so on.

Farmer John milks cow 33 first, giving up on cow 44 since she cannot be milked by her deadline due to the conflict with cow 33. Farmer John then milks cows 11 and 22.