#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) {
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});
stops.push_back({d, 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:11: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]
11 | for (int i = 1; i < stops.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
6812 KB |
Output is correct |
2 |
Correct |
130 ms |
6788 KB |
Output is correct |
3 |
Correct |
130 ms |
6824 KB |
Output is correct |
4 |
Correct |
138 ms |
6860 KB |
Output is correct |
5 |
Correct |
123 ms |
6824 KB |
Output is correct |
6 |
Correct |
133 ms |
6836 KB |
Output is correct |
7 |
Correct |
133 ms |
6720 KB |
Output is correct |
8 |
Correct |
125 ms |
6672 KB |
Output is correct |
9 |
Correct |
129 ms |
6644 KB |
Output is correct |
10 |
Correct |
126 ms |
6700 KB |
Output is correct |
11 |
Correct |
128 ms |
6620 KB |
Output is correct |
12 |
Correct |
125 ms |
6688 KB |
Output is correct |
13 |
Correct |
127 ms |
6700 KB |
Output is correct |
14 |
Correct |
131 ms |
6600 KB |
Output is correct |
15 |
Correct |
125 ms |
6688 KB |
Output is correct |
16 |
Correct |
126 ms |
6500 KB |
Output is correct |
17 |
Correct |
126 ms |
6580 KB |
Output is correct |
18 |
Correct |
128 ms |
6500 KB |
Output is correct |
19 |
Correct |
129 ms |
6580 KB |
Output is correct |
20 |
Correct |
128 ms |
6600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |