Deadline Homework

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
Memory limit: 977M

Problem type

You have n homework assignments to choose from. Each assignment takes exactly one hour to complete.

Assignment i has a deadline d_i and a score s_i. If you spend one full hour on it and finish by the end of hour d_i, you earn s_i 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 d_i and s_i, the deadline and score of one assignment.

Output

Print one integer: the maximum total score you can earn.

Constraints

  • 1 \le n \le 2 \cdot 10^5
  • 1 \le d_i \le 10^9
  • 1 \le s_i \le 10^9

Example 1

Input
4
4 70
1 80
1 30
2 100
Output
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

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

There are no comments at the moment.