No Time for Dragons

B. No Time for Dragons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One fairy king hated dragons to death. Not only that these monsters burn whole villages to ashes, kidnap princesses and guard treasures that they don't need at all, but they are also mentioned in statements of programming problems very often. To end their tyranny, he decided to recruit an army and destroy these damned creatures once and forever.

The king found out that there are n dragons in total, and to defeat the i-th of them he needs an army of ai soldiers, bi of which will be killed during the battle. Now he wants to know the minimal number of soldiers he needs to recruit in order to kill all the dragons. The king doesn't care about the order of battles: the only thing that matters is that none of the dragons will be left alive.

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of dragons.

Each of the next n lines contains two space-separated integers: ai and bi (1 ≤ bi ≤ ai ≤ 109) — the number of soldiers needed to defeat the i-th dragon, and the number of soldiers that will be killed in the battle against him.

Output

Output a single integer — the minimal number of soldiers that is sufficient to kill all the dragons.

Examples
input
2
7 4
5 1
output
8
input
3
4 1
6 4
5 3
output
10

/*
按殺龍要的人數與犧牲人數之差降序排列,在遍歷一遍即可。
*/
#include
#include
#include
using namespace std;
struct ss
{
    long long a;
    long long b;
}Dragon[200000];

int cmp(ss x,ss y)
{
    if(x.a-x.b>y.a-y.b)
        return 1;
    return 0;
}

int main()
{
    int n;
    long long ans=0;
    cin>>n;
    for(int i=0;i

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章