#K90802. Maximum Score Challenge

    ID: 37833 Type: Default 1000ms 256MiB

Maximum Score Challenge

Maximum Score Challenge

You are given a set of n problems, each characterized by a difficulty level and a score value. A contestant attempts the problems in increasing order of difficulty. Your task is to determine the maximum total score a contestant can achieve by solving all the problems in that order.

The input begins with an integer n, representing the number of problems. It is followed by n lines; each line contains two integers, where the first integer represents the difficulty level (which is used to order the problems) and the second integer is the score associated with that problem. Although the problems are provided in an arbitrary order, they must be considered in increasing order of difficulty when summing up the scores.

Note: Since all problems are solved, the maximum score is simply the sum of the scores of all problems. However, you must first sort the problems by their difficulty levels.

inputFormat

The first line of the input contains a single integer n (1 ≤ n ≤ 105), representing the number of problems.

The following n lines each contain two space-separated integers ai and bi (1 ≤ ai, bi ≤ 109), where ai is the difficulty of the i-th problem and bi is the score value of the problem.

outputFormat

Output a single integer, the maximum total score achieved after solving all the problems in the order of increasing difficulty.

## sample
4
4 2
5 10
6 6
7 18
36