Submission #337628

#TimeUsernameProblemLanguageResultExecution timeMemory
337628kutbilim_oneDivide and conquer (IZhO14_divide)C++14
100 / 100
39 ms6924 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define all(x) x.begin(),x.end() #define int long long const int MAXN = 100100; int x[MAXN], g[MAXN], d[MAXN], n; int prg[MAXN], prd[MAXN], mn[MAXN]; int ans; int search(int i, int E){ int l = 1, r = i, pos = 1; while(l < r){ int m = (l+r)>>1; if(mn[m] <= E) r = m; else l = m+1; } return r; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; i++) cin >> x[i] >> g[i] >> d[i]; mn[0] = 1e18; for(int i = 1; i <= n; i++){ prg[i] = g[i] + prg[i-1]; prd[i] = d[i] + prd[i-1]; mn[i] = min(mn[i-1], prd[i-1] - x[i]); int left = search(i, prd[i] - x[i]); ans = max(ans, prg[i] - prg[left-1]); } cout << ans << endl; return 0; }

Compilation message (stderr)

divide.cpp: In function 'long long int search(long long int, long long int)':
divide.cpp:15:23: warning: unused variable 'pos' [-Wunused-variable]
   15 |     int l = 1, r = i, pos = 1;
      |                       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...