#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
int n, d, a, b, x, l, r, m;
vector<tuple<int, int, int>> stops;
bool valid(int f) {
int cd = 0;
for (int i = 1; i < stops.size(); i++) {
tie(x, a, b) = stops[i];
f -= (x - get<0>(stops[i - 1]));
if (f < 0) return false;
if (f <= b) f += a;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> d;
for (int i = 0; i < n; i++) {
cin >> x >> a >> b;
if (x > d) continue;
stops.push_back({x, a, b});
}
stops.push_back({0, 0, 0});
sort(stops.begin(), stops.end());
l = 0, r = 1e9 + 5;
while (l + 1 != r) {
m = (l + r) / 2;
if (valid(m)) r = m;
else l = m;
}
cout << r << "\n";
}
Compilation message
FuelStation.cpp: In function 'bool valid(int)':
FuelStation.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for (int i = 1; i < stops.size(); i++) {
| ~~^~~~~~~~~~~~~~
FuelStation.cpp:11:9: warning: unused variable 'cd' [-Wunused-variable]
11 | int cd = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
14104 KB |
Output is correct |
2 |
Correct |
141 ms |
14060 KB |
Output is correct |
3 |
Correct |
159 ms |
13980 KB |
Output is correct |
4 |
Correct |
131 ms |
14136 KB |
Output is correct |
5 |
Correct |
131 ms |
14556 KB |
Output is correct |
6 |
Correct |
160 ms |
13524 KB |
Output is correct |
7 |
Correct |
136 ms |
13528 KB |
Output is correct |
8 |
Correct |
141 ms |
14116 KB |
Output is correct |
9 |
Correct |
178 ms |
14648 KB |
Output is correct |
10 |
Correct |
135 ms |
13576 KB |
Output is correct |
11 |
Correct |
134 ms |
13624 KB |
Output is correct |
12 |
Correct |
142 ms |
14064 KB |
Output is correct |
13 |
Correct |
129 ms |
13612 KB |
Output is correct |
14 |
Correct |
130 ms |
14132 KB |
Output is correct |
15 |
Correct |
130 ms |
14108 KB |
Output is correct |
16 |
Correct |
136 ms |
14620 KB |
Output is correct |
17 |
Correct |
136 ms |
14584 KB |
Output is correct |
18 |
Correct |
151 ms |
14144 KB |
Output is correct |
19 |
Correct |
133 ms |
14116 KB |
Output is correct |
20 |
Correct |
133 ms |
14124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |