# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337628 | kutbilim_one | Divide and conquer (IZhO14_divide) | C++14 | 39 ms | 6924 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |