# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338028 | BeanZ | Divide and conquer (IZhO14_divide) | C++14 | 36 ms | 3436 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.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 50;
long long mod = 1e9 + 7;
const int lim = 700;
const int lg = 18;
const int base = 311;
const long double eps = 1e-6;
ll sume[N], sumg[N], mn[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("tests.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n;
mn[0] = 1e18;
ll ans = 0;
for (int i = 1; i <= n; i++){
ll x, g, d;
cin >> x >> g >> d;
ll l = 1, h = i - 1;
sume[i] = sume[i - 1] + d;
sumg[i] = sumg[i - 1] + g;
ll cost = sume[i] - x;
while (l <= h){
ll mid = (l + h) >> 1;
if (mn[mid] > cost){
l = mid + 1;
} else {
h = mid - 1;
}
}
ans = max(ans, sumg[i] - sumg[l - 1]);
mn[i] = min(mn[i - 1], sume[i - 1] - x);
//cout << mn[i] << " " << cost << endl;
}
cout << ans;
}
/*
Ans:
Out:
*/
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... |