제출 #114412

#제출 시각아이디문제언어결과실행 시간메모리
114412lycArt Exhibition (JOI18_art)C++14
100 / 100
221 ms16140 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    using pll=pair<ll, ll>;
    int n; cin >> n;
    pll ab[n+1];
    FOR(i,1,n){
        ll a, b; cin >> a >> b;
        ab[i] = mp(a,b);
    }

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

    ll pre[n+1]; pre[0] = 0;
    FOR(i,1,n) pre[i] = pre[i-1] + ab[i].sc;
    // max S - (Amax-Amin)
    // max pre[i]-pre[j-1] - A[i] + A[j]
    ll maxi = 0, ans = 0;
    FOR(i,1,n){
        maxi = max(maxi, -pre[i-1]+ab[i].fi);
        ans = max(ans, pre[i]-ab[i].fi + maxi);
    }
    cout << ans << '\n';
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...