#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 1010 credits and must be submitted within 66 days, then to earn those 1010 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
11 11 66
22 77
33 33 22
44 11
55 22 44
66 55
77 66 11

The maximum credits that can be earned is 1515, with one possible order of completing the assignments being 2,6,3,1,7,5,42,6,3,1,7,5,4. 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 NN, representing the number of assignments;

The next NN 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 20%20\% of the data, N103N \leq 10^3;

For 40%40\% of the data, N104N \leq 10^4;

For 60%60\% of the data, N105N \leq 10^5;

For 100%100\% of the data, N106N \leq 10^6, and the deadlines for all assignments are less than 7×1057\times 10^5.