Submission #556148

#TimeUsernameProblemLanguageResultExecution timeMemory
556148ljubaArt Exhibition (JOI18_art)C++17
100 / 100
224 ms29228 KiB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll INF = 1e18 + 12;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<ll, ll>> temp(n);

    for(auto &z : temp) cin >> z.first >> z.second;

    sort(temp.begin(), temp.end());

    vector<pair<ll, ll>> v;
    ll suma = 0;
    v.push_back({0, suma});

    for(int i = 0, j = 0; i < n; i = j) {
        ll trenutno = 0;
        while(j < n && temp[i].first == temp[j].first) {
            trenutno += temp[j].second;
            ++j;
        }
        suma += trenutno;
        v.push_back({temp[i].first, suma});
    }

    ll ans = 0;

    n = int(v.size());

    //(pref[r] - pref[l-1]) - a[r] + a[l];
    //pref[r] - a[r] + (a[l] - pref[l-1])

    // for(auto &[a, b] : v) {
    //     cout << a << " " << b << endl;
    // }

    ll maksi = -INF;

    for(int i = 1; i < n; ++i) {
        maksi = max(maksi, v[i].first - v[i-1].second);
        ll tren = v[i].second - v[i].first;
        ans = max(ans, maksi + tren);
    }

    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...