Submission #782839

#TimeUsernameProblemLanguageResultExecution timeMemory
782839borisAngelovArt Exhibition (JOI18_art)C++17
100 / 100
151 ms20884 KiB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 500005;

int n;

pair<long long, long long> a[maxn];

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i].first >> a[i].second;
    }

    sort(a + 1, a + n + 1);

    long long sum = 0;
    long long preffix = (1LL << 62);
    long long ans = -(1LL << 62);

    for (int i = 1; i <= n; ++i)
    {
        preffix = min(preffix, sum - a[i].first);
        sum += a[i].second;
        ans = max(ans, sum - a[i].first - preffix);
    }

    cout << ans << endl;

    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...