시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 30 4 4 44.444%

문제

Farmer John has so very many jobs to do! In order to run the farm efficiently, he must make money on the jobs he does, each one of which takes just one time unit.

His work day starts at time 0 and has 1,000,000,000 time units (!).  He currently can choose from any of N (1 <= N <= 100,000) jobs conveniently numbered 1..N for work to do. It is possible but extremely unlikely that he has time for all N jobs since he can only work on one job during any time unit and the deadlines tend to fall so that he can not perform all the tasks.

Job i has deadline D_i (1 <= D_i <= 1,000,000,000). If he finishes job i by then, he makes a profit of P_i (1 <= P_i <= 1,000,000,000).

What is the maximum total profit that FJ can earn from a given list of jobs and deadlines?  The answer might not fit into a 32-bit integer.

입력

  • Line 1: A single integer: N
  • Lines 2..N+1: Line i+1 contains two space-separated integers: D_i and P_i

 

출력

  • Line 1: A single number on a line by itself that is the maximum possible profit FJ can earn.

 

예제 입력

3
2 10
1 5
1 7

예제 출력

17

힌트

Complete job 3 (1,7) at time 1 and complete job 1 (2,10) at time 2 to maximize the earnings (7 + 10 -> 17).