Assignments
InterviewTime limit1sMemory limit256 MB
Given deadlines and scores for N assignments, pick a subset schedulable within their deadlines to maximize total score.
Problem
Ungchan has many assignments to finish. He can finish one assignment per day, and each assignment has a deadline, so he may not be able to finish all of them. Finishing an assignment earns its score, but an assignment whose deadline has passed earns nothing.
Find the maximum total score Ungchan can earn.
Input
The first line contains the number of assignments ().
Each of the next lines describes one assignment with two integers () and (). Here is the number of days left until the deadline, so the assignment can only be finished on one of days 1 through . The value is the score earned by finishing it.
Output
Print the maximum total score on the first line.
Hint
In the first example, finishing the fifth, fourth, second, first, and seventh assignments in that order and giving up the third and sixth assignments earns 185 points.