poj 3045 Cow Acrobats

来源:互联网 发布:海马玩模拟器 for mac 编辑:程序博客网 时间:2024/05/08 09:20
/*贪心  风险值 =  w - (wnow + snow) * 使得(wnow+snow)最大即可 */#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define MAX_N 100010const int inf = 1 << 29;const int maxn = 5e4+100;struct cow{        int w;        int s;        bool operator < (const cow &a) const{                return w+s < a.w + a.s;        }}a[maxn];int n;long long sum;int main(){        while(scanf("%d", &n) != EOF){                sum = 0;                for(int i = 0;i < n ;i++){                        scanf("%d%d", &a[i].w, &a[i].s);                        sum += a[i].w;                }                sort(a, a + n);                long long ans = -inf;                for(int i = n-1;i >= 0; i--){                        sum -= a[i].w;          ans = max(ans, sum - a[i].s);                }                printf("%lld\n", ans);        }        return 0;}

0 0