#C8285. Minimum Total Task Completion Time

    ID: 52250 Type: Default 1000ms 256MiB

Minimum Total Task Completion Time

Minimum Total Task Completion Time

You are given n tasks where each task is represented by two integers: the priority and the execution time. In order to execute the tasks in an optimal order, you must sort the tasks by their priority in ascending order, and if two tasks have the same priority, sort them by their execution time in ascending order.

Once the tasks are optimally ordered, the minimum total time required to complete all the tasks is simply the sum of the execution times of all tasks:

T=i=1ntiT = \sum_{i=1}^{n} t_i

Your job is to compute and print the value of T given the list of tasks. Note that even though the ordering is important for the optimal schedule, since tasks are processed one after the other, the overall time is the sum of the individual execution times.

inputFormat

The first line contains a single integer n (1 ≤ n ≤ 105), the number of tasks. Each of the next n lines contains two integers p and t (1 ≤ p, t ≤ 109), representing the priority and execution time of a task, respectively.

outputFormat

Output a single integer, the minimum total time required to complete all tasks.## sample

3
1 3
2 2
1 1
6

</p>