Submission #1296724

#TimeUsernameProblemLanguageResultExecution timeMemory
1296724chithanhnguyenArt Exhibition (JOI18_art)C++20
100 / 100
125 ms12112 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second
#define __builtin_popcount __builtin_popcountll
#define all(x) (x).begin(), (x).end()

#define debug(a, l, r) for (int i = (l); i <= (r); ++i) cout << (a)[i] << ' '; cout << '\n';

struct Item{
    int a, b;
};

const int MAXN = 5e5 + 5;
int n, pref[MAXN]; Item items[MAXN];

void init() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a, b; cin >> a >> b;
        items[i] = {a, b};
    }

    sort(items + 1, items + n + 1, [] (const Item &i, const Item &j) {
        return i.a < j.a;
    });
}

void solve() {
    for (int i = 1; i <= n; ++i)
        pref[i] = pref[i - 1] + items[i].b;

    int mi = pref[0] - items[1].a;
    int res = -1e18 - 7;

    for (int i = 1; i <= n; ++i) {
        res = max(res, pref[i] - items[i].a - mi);
        mi = min(mi, pref[i] - items[i + 1].a);
    }

    cout << res;
}

signed main() {
    #ifdef NCTHANH
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

    init();
    solve();

    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...