poj3045 Cow Acrobats

答案有可能为负的。。。wa了好几发。

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=50005;
typedef pair<ll,ll> P;
P a[N];
bool cmp(const P&a,const P&b){
    return a.first+a.second<b.first+b.second;
}
int main(){
    int n;
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld%lld",&a[i].first,&a[i].second);        
    }
    sort(a+1,a+1+n,cmp);
    ll ans=-10 *(ll)0x7fffffff,sum=0;
    for(int i=1;i<=n;++i){
        ans=max(ans,sum-a[i].second);
        sum+=a[i].first;
    }
    printf("%lld",ans);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/Dream-Runner/p/10146223.html