Submission #1093121

#TimeUsernameProblemLanguageResultExecution timeMemory
1093121vjudge1Art Exhibition (JOI18_art)C++17
100 / 100
128 ms19028 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define lwb lower_bound
#define upb upper_bound
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x * y / __gcd(x, y)

const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int mxN = 5e5 + 5;
const int block = 450;
const int base = 311;
const int LOG = 19;

int n;
pair<ll, ll> a[mxN];
ll sum[mxN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].fi >> a[i].se;
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + a[i].se;
    }
    ll mn = a[1].fi;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, sum[i] - a[i].fi + mn);
        mn = max(mn, a[i + 1].fi - sum[i]);
    }
    cout << ans;
}
/*
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...