http://poj.org/problem?id=3045
2.Idea
Greedy approach is accepted. Order the cows in (W_i + S_i).
3.Source
int N;
struct Test {
ll w, s;
bool operator < (const Test &a)const {
return w + s < a.w + a.s;
}
} Tests[50004];
int main()
{
cin >> N;
for (int i = 0; i < N; i++) scanf("%d%d", &Tests[i].w, &Tests[i].s);
sort(Tests, Tests + N);
ll ans = -123456789;
ll cum = 0;
for (int i = 0; i < N; i++) {
ll tmp = cum - Tests[i].s;
cum += Tests[i].w;
ans = max(ans, tmp);
}
cout << ans << endl;
return 0;
}
No comments:
Post a Comment