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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> x(n + 1), g(n + 1, 0), d(n + 1, 0);
vector< pair<long long, int> > v;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> g[i] >> d[i];
g[i] += g[i - 1];
d[i] += d[i - 1];
v.push_back({d[i] - x[i], i});
}
sort(v.begin(), v.end());
vector<long long> a(n), mx(n);
for (int i = 0; i < n; i++) {
a[i] = v[i].first;
}
for (int i = n - 1; i >= 0; i--) {
mx[i] = g[v[i].second];
if (i < n - 1) {
mx[i] = max(mx[i], mx[i + 1]);
}
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
int j = lower_bound(a.begin(), a.end(), d[i - 1] - x[i]) - a.begin();
ans = max(ans, mx[j] - g[i - 1]);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |