Submission #1334382

#TimeUsernameProblemLanguageResultExecution timeMemory
1334382iamhereforfunArt Exhibition (JOI18_art)C++20
100 / 100
127 ms8260 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 5e5 + 5;
const int M = 1e6 + 5;
const int LG = 60;
const int INF = 1e9 + 5;
const int K = 301;
const int B = 150000;
const int MOD = 1e9 + 7;

int n;
pair<long long, long long> paint[N];
long long cur, ans, mn;

inline void solve()
{
    cin >> n;
    ans = 0;
    cur = 0;
    for (int x = 0; x < n; x++)
    {
        cin >> paint[x].first >> paint[x].second;
    }
    sort(paint, paint + n);
    mn = 1e18;
    for (int x = 0; x < n; x++)
    {
        mn = min(mn, -paint[x].first + cur);
        cur += paint[x].second;
        ans = max(ans, cur - mn - paint[x].first);
        // cout << cur << "\n";
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        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...