1008
#?include?<cstdio>
#?include?<algorithm>
#?define?N?100005
typedef?__int64?LL;
int?n;
int?a[N],?b[N],?r[N];
bool?cmp(int?x,?int?y)
{
????????????????return?a[x]-b[y]?==?a[y]-b[x]???a[x]>a[y]?:?a[x]-b[y]>a[y]-b[x];
}
int?main()
{
????????????????freopen("in.txt",?"r",?stdin);
????????????????int?i;
????????????????LL?w,?ans;
????????????????while?(~scanf("%d",?&n))
????????????????{
????????????????????????????????for?(i?=?0;?i?<?n;?++i)
????????????????????????????????????????????????scanf("%d%d",?&a[i],?&b[i]),?r[i]?=?i;
????????????????????????????????std::sort(r,?r+n,?cmp);
????????????????????????????????w?=?a[?r[n-1]?];
????????????????????????????????ans?=?0;
????????????????????????????????for?(i?=?n-2;?i?>=?0;?--i)
????????????????????????????????{
????????????????????????????????????????????????if?(ans?<?w-(LL)b[?r[i]?])?ans?=?w?-?(LL)b[?r[i]?];
????????????????????????????????????????????????w?+=?(LL)a[?r[i]?];
????????????????????????????????}
????????????????????????????????printf("%I64d\n",?ans);
????????????????}
????????????????return?0;
}
posted on 2012-09-16 17:06
yajunw 閱讀(186)
評論(0) 編輯 收藏 引用