hdu 4296 贪心水题 轮换不等式;

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int maxn = 100010;

int n;
struct node{
    int w,s;
}floor[maxn];

int cmp(node a,node b){
     return a.w-b.s < b.w - a.s;   
}
int main()
{
    //if(freopen("input.txt","r",stdin)== NULL)  {printf("Error\n"); exit(0);}
    
    while(scanf("%d",&n) !=  EOF){
        for(int i=0;i<n;i++)
            scanf("%d%d",&floor[i].w,&floor[i].s);
    
        sort(floor,floor+n,cmp); 
        long long int ans = 0;
        long long int sum = 0;
        for(int i=0;i<n;i++){
            ans = max(ans,sum-floor[i].s);
            sum += floor[i].w;
        }
        if(ans < 0) printf("0\n");
        else         printf("%I64d\n",ans);
    }
    return 0;
}

 

posted @ 2013-05-23 21:19  等待最好的两个人  阅读(159)  评论(0编辑  收藏  举报