이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6 + 5, M = 2e14;
int n;
ll x[N], g[N], d[N];
map<ll, ll> tree;
void upd(ll k, ll x) {
while (k < M) {
if (tree.find(k) == tree.end()) {
tree[k] = x;
} else {
tree[k] = min(tree[k], x);
}
k += k & -k;
}
}
ll que(ll k) {
ll ans = LLONG_MAX;
while (k) {
if (tree.find(k) != tree.end()) {
ans = min(ans, tree[k]);
}
k -= k & -k;
}
return ans;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> g[i] >> d[i];
d[i] += d[i - 1];
g[i] += g[i - 1];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
upd(d[i - 1] - x[i] + M / 2, g[i - 1]);
ans = max(ans, g[i] - que(d[i] - x[i] + M / 2));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |