Deadline Homework
View as PDFYou have homework assignments to choose from. Each assignment takes exactly one hour to
complete.
Assignment has a deadline
and a score
. If you spend one full hour on it and finish
by the end of hour
, you earn
points. Otherwise, you earn nothing for that assignment.
You can work on at most one assignment in each hour, and you do not have to complete every assignment.
What is the maximum total score you can earn?
Input
The first line contains an integer , the number of assignments.
The next lines each contain two integers
and
, the deadline and score of one
assignment.
Output
Print one integer: the maximum total score you can earn.
Constraints
Example 1
Input
4
4 70
1 80
1 30
2 100
Output
250
Explanation
One optimal schedule is:
- hour
: take the assignment with deadline
and score
- hour
: take the assignment with deadline
and score
- hour
: take the assignment with deadline
and score
This earns points.
Example 2
Input
5
1 10
1 20
1 30
1 40
1 50
Output
50
Example 3
Input
6
2 50
2 10
3 20
3 30
3 40
100 60
Output
180
Comments