Submission #249725

#TimeUsernameProblemLanguageResultExecution timeMemory
249725MarcoMeijerArt Exhibition (JOI18_art)C++14
100 / 100
267 ms28792 KiB
#include <bits/stdc++.h> using namespace std; //macros typedef long long ll; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define INF 1e9 #define pb push_back #define fi first #define se second #define sz size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //===================// // Added libraries // //===================// //===================// //end added libraries// //===================// void program(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); program(); } //===================// // begin program // //===================// const int MX = 7e5; ll n, a[MX], b[MX]; ll SA[MX]; ll sm[MX]; void program() { cin>>n; RE(i,n) cin>>a[i]>>b[i]; RE(i,n) SA[i]=i; sort(SA,SA+n, [](int i, int j) { return a[i]<a[j]; }); sm[0] = 0; RE(i,n) sm[i+1] = sm[i]+b[SA[i]]; ll ans = 0; ll mx = a[SA[0]]-sm[0]; RE(i,n) { mx = max(mx, a[SA[i]]-sm[i]); ans = max(ans, sm[i+1]-a[SA[i]]+mx); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...