제출 #405211

#제출 시각아이디문제언어결과실행 시간메모리
405211LoboArt Exhibition (JOI18_art)C++17
100 / 100
235 ms24876 KiB
#include <bits/stdc++.h>
 
using namespace std;

const long long INFll = 1e18;
const int INFii = 1e9;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back

#define maxn 550000
//LEMBRAR DE MUDAR

ll n, ps[maxn];
pair<ll,ll> a[maxn];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("in.in", "r", stdin);
    //freopen("____.out", "w", stdout);

    cin >> n;

    for(ll i = 1; i <= n; i++) {
        cin >> a[i].fr >> a[i].sc;
    }

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

    for(ll i = 1; i <= n; i++) 
        ps[i] = ps[i-1] + a[i].sc;


    ll best = -INFll;
    ll ans = 0;
    for(ll i = n; i >= 1; i--) {
        best = max(best, ps[i] - a[i].fr);
        ans = max(ans, best - ps[i-1] + a[i].fr);
    }
    
    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...