Submission #1304884

#TimeUsernameProblemLanguageResultExecution timeMemory
1304884polishprogrammerArt Exhibition (JOI18_art)C++20
100 / 100
125 ms8260 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<ll, ll>> obrazy(n);
    for (int i = 0; i < n; i++) {
        cin >> obrazy[i].fi >> obrazy[i].se;
    }
    sort(obrazy.begin(), obrazy.end());
    ll best = -1e18, s = 0, wyn = 0;
    for (int i = 0; i < n; i++) {
        ll wiel = obrazy[i].fi, war = obrazy[i].se;
        best = max(best, wiel - s);
        s += war;
        wyn = max(wyn, best + s - wiel);
    }
    cout << wyn;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...