Submission #765894

#TimeUsernameProblemLanguageResultExecution timeMemory
765894Owen11Art Exhibition (JOI18_art)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; # define int long long # define fir first # define sec second # define pb push_back const int cnst = 5e5+5; bool mutipletestcase = 0; //bool debug = false; int arr[cnst]; int posi[cnst*4]; int merge(int a, int b) { return max(a, b); } void build(int a, int b, int id) { if(a == b) {posi[id] = arr[a]; return;} int mid = (a+b)/2; build(a, mid, id*2); build(mid+1, b, id*2+1); posi[id] = merge(posi[id*2], posi[id*2+1]); } void update(int a, int b, int id, int pos, int val) { if(a == pos && b == pos) { posi[id] = val; return; } int mid =(a+b)/2; if(pos <= mid) update(a, mid, id*2, pos, val); else update(mid+1, b, id*2+1, pos, val); posi[id] = merge(posi[id*2], posi[id*2+1]); } int get(int a, int b, int id, int from, int to) { if(to < a || from > b) return 0; if(from <= a && b <= to) return posi[id]; int mid = (a+b)/2; return merge(get(a, mid, id*2, from, to), get(mid+1, b, id*2+1, from, to)); } void solve() { int n; cin >> n; pair<int, int> paint[n+5]; for(int i = 1; i<=4*n; i++) posi[i] = LONG_MIN; for(int i = 1; i<=n; i++) cin >> paint[i].fir >> paint[i].sec; int presum[n+5]; presum[0] = 0; sort(paint+1, paint+n+1); for(int i = 1; i<=n; i++) { presum[i] = presum[i-1]+paint[i].sec; update(1, n, 1, i, presum[i]-paint[i].fir); } int ans = 0; for(int i = 1; i<=n; i++) { int temp = paint[i].fir-presum[i-1]; temp += get(1, n, 1, i, n); ans = max(ans, temp); } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); int t = 1; if(mutipletestcase) cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...