题目:
http://poj.org/problem?id=3045
思路:
贪心.
CODE:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct node {
int w, s;
bool operator < (const node& x) const {
return x.w + x.s < w + s;
}
};
node cow[50016];
int n;
int main()
{
//freopen("in", "r", stdin);
scanf("%d", &n);
int sum = 0;
for(int i = 0; i < n; ++i) {
scanf("%d %d", &cow[i].w, &cow[i].s);
sum += cow[i].w;
}
sort(cow, cow + n);
int ans = 0x80808080;
for(int i = 0; i < n; ++i) {
sum -= cow[i].w;
ans = max(ans, sum - cow[i].s);
}
printf("%d\n", ans);
return 0;
}