Submission #887063

#TimeUsernameProblemLanguageResultExecution timeMemory
887063ByeWorldArt Exhibition (JOI18_art)C++14
100 / 100
139 ms29088 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #define bupol __builtin_popcount #define int long long #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) using namespace std; const int MAXN = 5e5+20; const int LOG = 20; const int MOD = 1e9+7; const int SQRT = 520; const int INF = 1e18; typedef pair<int,int> pii; typedef pair<int,pii> ipii; int n; vector <pii> vec; int a[MAXN], mx[MAXN]; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i=1; i<=n; i++){ int x, y; cin >> x >> y; vec.pb({x, y}); } vec.pb({-1, -1}); sort(vec.begin(), vec.end()); a[1] = vec[1].se; for(int i=2; i<=n; i++){ a[i] = a[i-1]; a[i] += vec[i].se; a[i] -= vec[i].fi-vec[i-1].fi; //cout << i << ' ' << a[i] << " te\n"; } mx[n+1] = -INF; for(int i=n; i>=1; i--) mx[i] = max(mx[i+1], a[i]); int ans = 0, te = 0; for(int i=1; i<=n; i++){ //cout << i << ' ' << mx[i] << ' ' << te << " te\n"; ans = max(ans, mx[i]+te); te -= vec[i].se; te += vec[i+1].fi-vec[i].fi; } 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...