Deadline Homework
You have n homework assignments to choose from. Each assignment takes exactly one hour to complete.
Assignment i has a deadline di and a score si. If you spend one full hour on it and finish by the end of hour di, you earn si 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 n, the number of assignments.
The next n lines each contain two integers di and si, the deadline and score of one assignment.
Output
Print one integer: the maximum total score you can earn.
Constraints
- 1≤n≤2⋅105
- 1≤di≤109
- 1≤si≤109
Example 1
4
4 70
1 80
1 30
2 100
250
Explanation
One optimal schedule is:
- hour 1: take the assignment with deadline 1 and score 80
- hour 2: take the assignment with deadline 2 and score 100
- hour 3: take the assignment with deadline 4 and score 70
This earns 80+100+70=250 points.
Example 2
5
1 10
1 20
1 30
1 40
1 50
50
Example 3
6
2 50
2 10
3 20
3 30
3 40
100 60
180
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.