Submission #1088902

#TimeUsernameProblemLanguageResultExecution timeMemory
1088902HienTDArt Exhibition (JOI18_art)C++14
50 / 100
1041 ms25416 KiB
#include <bits/stdc++.h>
using namespace std;

//#define USACO

#define             fi  first
#define             se  second
#define           TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define         ALL(v)  (v).begin(), (v).end()
#define         BIT(x)  (1LL << (x))
#define     MASK(x, i)  (((x) >> (i)) & 1)
#define   FOR(i, a, b)  for(int i = (a), _b = (b); i <= _b; ++ i)
#define  FORD(i, b, a)  for(int i = (b), _a = (a); i >= _a; -- i)

const string NAME = "BAITAP";

const string name = "";

const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int mod = 998244353;

const int mxN = 5e5 + 5;

int N;
vector<pair<long long, long long>> A(mxN);

void init(void){
    cin >> N;
    FOR(i, 1, N) cin >> A[i].fi >> A[i].se;
}

struct cmp{
    bool operator() (const pair<long long, long long> &a, const pair<long long, long long> &b){
        return (a.fi != b.fi ? a.fi < b.fi : a.se > b.se);
    }
};

void process(void){
    long long ans = -INF;
    long long mx = -INF;
    sort(A.begin() + 1, A.begin() + 1 + N, cmp());
    FOR(i, 1, N) cerr << i << ' ' << A[i].fi << ' ' << A[i].se << '\n';
    FOR(i, 1, N){
        A[i].se += A[i - 1].se;
        mx = max(A[i].fi - A[i - 1].se, mx);
        ans = max(A[i].se - A[i].fi + mx, ans);
        cerr << i << ' ' << A[i].fi << ' ' << A[i].se << ' ' << mx << ' ' << ans << '\n';
    }
    cout << ans;
}

signed main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef LOCAL
        freopen((NAME + ".INP").c_str(), "r", stdin);
        freopen((NAME + ".OUT").c_str(), "w", stdout);
    #elif defined(USACO)
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    #endif // I/O

    init();
    process();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...