posts - 16,comments - 0,trackbacks - 0
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 阅读(160) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理