이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 100000
int x[MAXN], g[MAXN], d[MAXN], n;
int prg[MAXN], prd[MAXN];
int ans = 0;
bool can (int GOLD) {
for (int l = 0; l < n; l++) {
int r = lower_bound(prg, prg + n, (l?prg[l-1]:0) + GOLD) - prg;
if (r >= 0 && r < n) {
if (x[r] - x[l] <= prd[r] - (l?prd[l-1]:0)) {
ans = max(ans, prg[r] - (l?prg[l-1]:0));
return true;
}
}
}
return false;
}
signed main() {
//ios::sync_with_stdio(0);
//cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> g[i] >> d[i];
}
for (int i = 0; i < n; i++) {
prg[i] = g[i];
prd[i] = d[i];
if (i)
prg[i] += prg[i - 1],
prd[i] += prd[i - 1];
}
int l = 0, r = prg[n - 1];
while (l <= r) {
int GOLD = (l + r) / 2;
if (can (GOLD)) {
l = GOLD + 1;
} else {
r = GOLD - 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... |