This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 7;
ll x[N], g[N], d[N], mx[N];
int main() {
int n;cin >> n;
for(int i = 1;i <= n;i++) {
cin >> x[i] >> g[i] >> d[i];
g[i] += g[i-1], d[i] += d[i-1];
}
ll l = 0, r = 1e15, ans = -1;
while(l <= r) {
ll mid = l + (r - l) / 2;
ll ok = 0;
for(int i = 1;i <= n;i++) {
mx[i] = max(mx[i - 1], x[i]- d[i - 1]);
ll _l = 0, _r = i - 1, pos = -1;
while(_l <= _r) {
ll _m = _l + (_r - _l) / 2;
if(g[i] - g[_m] >= mid) pos = _m, _l = _m + 1;
else _r = _m - 1;
}
if(pos == -1) continue;
if(x[i] - d[i] <= mx[pos + 1]) {
ok = 1;
break;
}
}
if(ok) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |