Submission #741996

#TimeUsernameProblemLanguageResultExecution timeMemory
741996TheOpChickenDivide and conquer (IZhO14_divide)C++17
100 / 100
123 ms7976 KiB
#include <iostream> using namespace std; const long long maxN = 1e5 + 5, inf = 1e18; pair<int, pair<int, int> > arr[maxN]; long long sg[4*maxN], pref_diff[maxN], pref_gold[maxN]; void build(int idx, int nl, int nr){ if (nl == nr){ sg[idx] = pref_diff[nl]; return; } int mid = (nl + nr)/2; build(2*idx, nl, mid); build(2*idx+1, mid+1, nr); sg[idx] = max(sg[2*idx], sg[2*idx+1]); } int query(int idx, int nl, int nr, int need){ if (nl == nr) return nl; int mid = (nl + nr)/2; if (sg[2*idx+1] >= need) return query(2*idx+1, mid+1, nr, need); return query(2*idx, nl, mid, need); } int main(){ int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second; pref_diff[0] = arr[0].second.second; for (int i = 1; i < n; i++) pref_diff[i] = pref_diff[i-1] + arr[i].second.second - (arr[i].first - arr[i-1].first); pref_gold[0] = arr[0].second.first; for (int i = 1; i < n; i++) pref_gold[i] = pref_gold[i-1] + arr[i].second.first; build(1, 0, n-1); long long mx = pref_gold[query(1, 0, n-1, 0)]; for (int i = 1; i < n; i++){ long long cur = pref_gold[query(1, 0, n-1, pref_diff[i]-arr[i].second.second)] - pref_gold[i-1]; mx = max(cur, mx); } cout << mx << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...