IT民工
加油!

让上面的w和s都尽可能小,即w+s升序排序,值小的放在上面。这样一来,不管是w很大s很小或者s很大w很小,都可以使得最大的PDV尽可能地小,可以用笔写写看。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef __int64 LL;
const int MAXN = 100100;
int n;
struct Node
{
    LL w, s;
}t[MAXN];

bool cmp(const Node a, const Node b)
{
    return a.w + a.s < b.w + b.s;
}

int main()
{
    while(scanf("%d", &n) != EOF)
    {
        for(int i = 0; i < n; i ++)
        {
            scanf("%I64d%I64d", &t[i].w, &t[i].s);
        }
        sort(t, t + n, cmp);
        LL e = t[0].w;
        LL ans = - t[0].s;
        for(int i = 1; i < n; i ++)
        {
            LL tt = e - t[i].s;
            e += t[i].w;
            if(tt > ans) ans = tt;
        }
        if(ans < 0) puts("0");
        else printf("%I64d\n", ans);
    }
    return 0;
}
posted on 2012-09-16 17:35  找回失去的  阅读(1262)  评论(0编辑  收藏  举报