Submission #1016570

#TimeUsernameProblemLanguageResultExecution timeMemory
1016570phongArt Exhibition (JOI18_art)C++17
100 / 100
128 ms16088 KiB
#include<bits/stdc++.h>

#define ll long long
const int nmax = 5e5 + 5, N = 4e5;
const ll oo = 1e18;
const int lg = 18, M = 4e3;
const int base = 2e5, mod = 1e9 + 7;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';cout << endl
using namespace std;

int n;
pii a[nmax];
ll s[nmax], pre[nmax];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i].fi >> a[i].se;
    sort(a +1 , a + 1 + n);
    pre[0] = -oo;

    ll ans = -oo;
    for(int i = 1; i <= n; ++i){
        s[i] = s[i - 1] + a[i].se;
        pre[i] = max(pre[i - 1], -s[i - 1] + a[i].fi);

        ans = max(ans, s[i] - a[i].fi + pre[i]);
    }
    cout << ans;
}
/*
15
1543361732 260774320
2089759661 257198921
1555665663 389548466
4133306295 296394520
2596448427 301103944
1701413087 274491541
2347488426 912791996
2133012079 444074242
2659886224 656957044
1345396764 259870638
2671164286 233246973
2791812672 585862344
2996614635 91065315
971304780 488995617
1523452673 988137562

*/

Compilation message (stderr)

art.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...