Submission #647159

#TimeUsernameProblemLanguageResultExecution timeMemory
647159danikoynovArt Exhibition (JOI18_art)C++14
100 / 100
598 ms21012 KiB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 5e5 + 10;

struct element
{
    ll v, s;

    bool operator < (const element &e) const
    {
        return s < e.s;
    }
}e[maxn];

int n;

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        cin >> e[i].s >> e[i].v;
    }

    sort(e + 1, e + n + 1);
    ll p = 0, b = -1e18, ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        b = max(b, - p + e[i].s);
        p = p + e[i].v;
        ans = max(ans, p - e[i].s + b);
        ///cout << b << " " << i << endl;
    }

    cout << ans << endl;

}

int main()
{
    solve();
    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...