#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> X(N), G(N), D(N);
for (int i = 0; i < N; i++)
cin >> X[i] >> G[i] >> D[i];
vector<int64_t> pref_gold(N);
for (int i = 0; i < N; i++)
pref_gold[i] = G[i] + (i > 0 ? pref_gold[i - 1] : 0);
vector<int64_t> pref_energy(N);
for (int i = 0; i < N; i++)
pref_energy[i] = D[i] + (i > 0 ? pref_energy[i - 1] : 0);
auto Check = [&](long long val) -> bool {
for (int i = 0; i < N; i++) {
int bot = i, top = N - 1, pos = N;
while (bot <= top) {
int mid = (bot + top) / 2;
if (pref_gold[mid] - (i == 0 ? 0 : pref_gold[i - 1]) >= val)
pos = mid, top = mid - 1;
else
bot = mid + 1;
}
if (pos == N)
continue;
if (pref_energy[pos] - (i == 0 ? 0 : pref_energy[i - 1]) >= X[pos] - X[i])
return true;
}
return false;
};
int64_t bot = 0, top = accumulate(G.begin(), G.end(), 0), ans = 0;
while (bot <= top) {
int64_t mid = (bot + top) / 2;
if (Check(mid))
ans = mid, bot = mid + 1;
else
top = mid - 1;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |