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>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 2e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<ll> x(n + 1), g(n + 1), e(n + 1);
for (int i = 1; i <= n; i++) {
cin >> x[i] >> g[i] >> e[i];
g[i] += g[i - 1];
e[i] += e[i - 1];
}
vector<ll> pref(n + 1);
for (int i = 1; i <= n; i++) pref[i] = max(pref[i - 1], x[i] - e[i - 1]);
ll ans = 0;
for (int i = 1; i <= n; i++) {
int l = 1; int r = i; int id = -1;
while (l <= r) {
int mid = l + r >> 1;
if (pref[mid] >= x[i] - e[i]) {
r = mid - 1;
id = mid;
}
else l = mid + 1;
}
if (id == -1) continue;
smax(ans, g[i] - g[id - 1]);
}
cout << ans << en;
return 0;
}
Compilation message (stderr)
divide.cpp: In function 'int main()':
divide.cpp:28:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |