Submission #1150433

#TimeUsernameProblemLanguageResultExecution timeMemory
1150433tvgkArt Exhibition (JOI18_art)C++20
0 / 100
0 ms324 KiB
#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 5e5 + 7;

int n;
ll pre[mxN], mx[mxN];
ii a[mxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);

    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++)
        pre[i] = pre[i - 1] + a[i].se;

    ll ans = 0;
    for (int i = n; i >= 1; i--)
    {
        mx[i] = max(mx[i + 1], pre[i] - a[i].fi);
        ans = max(ans, mx[i] - pre[i - 1] + a[i].fi);
    }
    cout << ans << endl;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...