Submission #1281262

#TimeUsernameProblemLanguageResultExecution timeMemory
1281262i_love_kim_ji_wonArt Exhibition (JOI18_art)C++20
100 / 100
146 ms12172 KiB
// I ♡ 김지원
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define freopen(name) if(fopen(name".INP","r")) {freopen (name".INP","r",stdin); freopen (name".OUT","w",stdout);}
using namespace std;

using ll = long long;

void justDoIt();

int main() {
    // freopen("");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    justDoIt();
    return 0;
}

const int N = 5e5 + 5;

pair<ll, int> a[N];
ll pre[N];

void test() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + max(a[i].second, 0);
    }
    ll cur = -1e18, res = -1e18;
    for (int i = 1; i <= n; i++) {
        cur = max(cur, a[i].first - pre[i - 1]);
        res = max(res, pre[i] - a[i].first + cur);
    }
    cout << res;
}

void justDoIt() {
    int t = 1;
    // cin >> t;
    for (int tests = 1; tests <= t; tests++) {
        test();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...