#Q9. 「一本通 1.1 练习 4」家庭作业
「一本通 1.1 练习 4」家庭作业
Description
On the first day of school, the teacher assigned all the homework. Each assignment will earn credits only if it is submitted within the specified deadline. The deadlines and credits for each assignment may vary. For example, if an assignment is worth credits and must be submitted within days, then to earn those credits, the assignment must be submitted by the end of the 6th day.
Each assignment takes exactly one day to complete. For instance, suppose there are 7 assignments with their respective deadlines and credits as follows:
| Assignment No. | Deadline | Credits |
|---|---|---|
The maximum credits that can be earned is , with one possible order of completing the assignments being . Note that there may be other methods.
Your task is to find an order of completing the assignments that maximizes the total credits earned.
Input Format
The first line contains an integer , representing the number of assignments;
The next lines each contain two integers: the first integer indicates the deadline of the assignment, and the second integer indicates the credits for that assignment.
Output Format
Output an integer representing the maximum credits that can be earned. It is guaranteed that the answer does not exceed the range of int in C/C++.
Sample 1
7
1 6
1 7
3 2
3 1
2 4
2 5
6 1
15
Constraints & Hints
For of the data, ;
For of the data, ;
For of the data, ;
For of the data, , and the deadlines for all assignments are less than .