Submission #441194

#TimeUsernameProblemLanguageResultExecution timeMemory
441194julian33Art Exhibition (JOI18_art)C++14
100 / 100
235 ms28716 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) { cerr<<vars<<" = "; string delim=""; (...,(cerr<<delim<<values,delim=", ")); cerr<<"\n"; } #else #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) {} #endif #define pb push_back #define sz(x) (int)(x.size()) typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<typename T> inline void maxa(T& a,T b){a=max(a,b);} template<typename T> inline void mina(T& a,T b){a=min(a,b);} int main(){ cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin>>n; vector<pll> art; ll sum=0; for(int i=0;i<n;i++){ ll a,b; cin>>a>>b; sum+=b; art.pb({a,b}); } sort(art.begin(),art.end()); vector<ll> psa(n+1),pref(n+1); for(int i=1;i<=n;i++){ psa[i]=art[i-1].second+psa[i-1]; } pref[0]=-art[0].first; for(int i=1;i<n;i++){ pref[i]=min(psa[i]-art[i].first,pref[i-1]); } ll ans=0; for(int i=n;i>=1;i--){ maxa(ans,psa[i]-art[i-1].first-pref[i-1]); } 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...