hdu4219-Buildings(2012chengdu online I题)(贪心)




#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<queue>
#include <deque>
#include <list>
#include <ctime>
#include <stack>
#include <vector>
#include<set>
#define Maxn 100500
typedef long long ll;
#define FOR(i,j,n) for(int i=j;i<=n;i++)
#define DFR(i,j,k) for(int i=j;i>=k;--i)
#define lowbit(a) a&-a
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
using namespace std;
struct f
{
    int w,s;

}f[Maxn];
bool cmp( struct f a,struct f b)
{
    return a.s+a.w<b.s+b.w;
}
int main()
{   int n;
    while(~scanf("%d",&n))
    {   FOR(i,1,n)
        scanf("%d%d",&f[i].w,&f[i].s);
        sort(f+1,f+1+n,cmp);
        ll maxx=0,sum=0;
        FOR(i,1,n)
        {
            maxx=Max(maxx,sum-f[i].s);
            sum+=f[i].w;
        }
        printf("%I64d\n",maxx);
    }
    return 0;
}






你可能感兴趣的:(hdu4219-Buildings(2012chengdu online I题)(贪心))