Problem list
Log in
#usaco0117 · USACO 2013-2014 December Silver

Milk Scheduling (Deadlines)

Gold III 2.0 s 256 MB

Farmer John has N cows that need to be milked (1 <= N <= 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. More specifically, cow i produces g_i gallons of milk (1 <= g_i <= 1000), but only if she is milked before a deadline at time d_i (1 <= d_i <= 10,000). Time starts at t=0, so at most x total cows can be milked prior to a deadline at time t=x.

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

Input

  • Line 1: The value of N.
  • Lines 2..1+N: Line i+1 contains the integers g_i and d_i.

Output

The maximum number of gallons of milk Farmer John can obtain.

Example 1

Input
4
10 3
7 5
8 1
2 1
Output
25

Output details: FJ milks cow 3 first (giving up cow 4), then cows 1 and 2.

Source
USACO 2013-2014 December Silver
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code