3 10 6 2 3 5 4 2 2 2 2 2 3 10 3 2 5 3 3
1 0 2
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100000 + 10
#define INF 0x3f3f3f3f
#define LL long long
struct E
{
int w, s;
}e[N];
int n;
int cmp(E a, E b)
{
return a.s + a.w < b.s + b.w ;
}
int main()
{
while(~scanf("%d", &n))
{
for(int i = 1; i <= n; i++)
{
scanf("%d%d", &e[i].w, &e[i].s);
}
sort(e + 1, e + 1 + n, cmp);
LL tmp = e[1].w;
LL ans = -INF;
for(int i = 2; i <= n; i++)
{
LL t = tmp - e[i].s;
ans = max(ans, t);
tmp += e[i].w;
}
if(ans < 0)
printf("0\n");
else printf("%I64d\n", ans);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/dojintian/article/details/47981205