Submission #1087341

#TimeUsernameProblemLanguageResultExecution timeMemory
1087341f0rizenArt Exhibition (JOI18_art)C++17
100 / 100
133 ms25056 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

int32_t main() {
#ifdef LOCAL
    freopen("/tmp/input.txt", "r", stdin);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    vector<pair<ll, int>> v(n);
    for (auto &[a, b] : v) {
        cin >> a >> b;
    }
    sort(v.begin(), v.end());
    vector<ll> pref(n + 1);
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + v[i - 1].second;
    }
    ll mn = -infll;
    ll ans = -infll;
    for (int i = 0; i < n; ++i) {
        mn = max(mn, -pref[i] + v[i].first);
        ans = max(ans, pref[i + 1] - v[i].first + mn);
    }
    cout << ans << "\n";
    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...