이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |