Submission #729349

#TimeUsernameProblemLanguageResultExecution timeMemory
729349PringArt Exhibition (JOI18_art)C++14
50 / 100
1033 ms24564 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> pii;

struct P {
    int sz, val;
    P() {
        sz = 0;
        val = 0;
    }
    P(int _sz, int _val) {
        sz = _sz;
        val = _val;
    }
};

const int MXN = 500005;
int n, ans = 0;
P art[MXN];
int pre[MXN];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> art[i].sz >> art[i].val;
    }
    sort(art, art + n, [](P &a, P &b) {
        return (a.sz == b.sz ? a.val < b.val : a.sz < b.sz);
    });
    for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + art[i].val;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            ans = max(ans, pre[j] - pre[i] - (art[j - 1].sz - art[i].sz));
        }
    }
    cout << ans << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...