#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<long long> X(N), G(N), D(N);
for (int i = 0; i < N; i++)
cin >> X[i] >> G[i] >> D[i];
vector<long long> pref_gold(N);
for (int i = 0; i < N; i++)
pref_gold[i] = G[i] + (i > 0 ? pref_gold[i - 1] : 0);
vector<long long> 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 >> 1;
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;
};
long long bot = 1, top = pref_gold[N - 1], ans = 0;
while (bot <= top) {
long long mid = bot + top >> 1;
if (Check(mid))
ans = mid, bot = mid + 1;
else
top = mid - 1;
}
cout << ans << "\n";
}
Compilation message
divide.cpp: In lambda function:
divide.cpp:27:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | int mid = bot + top >> 1;
| ~~~~^~~~~
divide.cpp: In function 'int main()':
divide.cpp:46:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | long long mid = bot + top >> 1;
| ~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |