1 条题解

  • 0
    @ 2026-2-10 14:20:29
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    struct node{
        int w,s;
    };
    node t[50010];
    bool cmp(node a, node b){
        return a.w + a.s < b.w + b.s;
    }
    signed main(){
        int n;
        cin >> n;
        for (int i = 0;i < n;i++){
            int x,y;
            cin >> x >> y;
            t[i].w = x;
            t[i].s = y;
        }
        sort (t,t + n,cmp);
        long long h = 0;
        long long f = -1e9-10;
        long long g = 0;
        for (int i = 0;i < n;i++){
            h = g - t[i].s;
            if (h > f){
                f = h;
            }
            g += t[i].w;
        }
        cout << f;
        return 0;
    }
    
    
    • 1

    信息

    ID
    4355
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    61
    已通过
    14
    上传者