Submission #729354

#TimeUsernameProblemLanguageResultExecution timeMemory
729354PringArt Exhibition (JOI18_art)C++14
100 / 100
284 ms33256 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 a[MXN];
int pre[MXN];

priority_queue<pii> pq;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].sz >> a[i].val;
    }
    sort(a, a + 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] + a[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;
    for (int j = 1; j <= n; j++) pq.push({pre[j] - a[j - 1].sz, j});
    for (int i = 0; i < n; i++) {
        while (pq.top().second <= i) pq.pop();
        ans = max(ans, a[i].sz - pre[i] + pq.top().first);
    }
    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...