Submission #1106083

#TimeUsernameProblemLanguageResultExecution timeMemory
1106083ngokhanhArt Exhibition (JOI18_art)C++17
100 / 100
137 ms20844 KiB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define rev2(i,a,b,c) for (int i=a;i>=b;i-=c)
#define ii pair<ll,ll>
#define bit(i,j) ((i>>j)&1)
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define ll long long
#define F first
#define S second
#define sz(a) (int)(a.size())
#define on(n) __builtin_popcountll(n)
#define ld long double
#define __log2(x) 63-__builtin_clzll(x)
#define Mask(x) (1LL<<x)
#define ALL(v) v.begin(),v.end()

const int N=5e5+5;
const int mod=998244353;

int n;
ii A[N];

void solution(){
    cin >> n;
    rep(i,1,n) cin >> A[i].F >> A[i].S;
    sort(A+1,A+1+n);
    ll S=0,res=LLONG_MIN,Min=LLONG_MAX;
    rep(i,1,n){
        Min=min(Min,S-A[i].F);
        S+=A[i].S;
        res=max(res,S-A[i].F-Min);
    }
    cout << res;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int test=1;
    //cin >> test;
    while(test--)
        solution();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...