#include <bits/stdc++.h>
#define fast_input_output() ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
using namespace std;
typedef long long ll;
long long const mod = 1e9 + 7;
ll n, d; vector<vector<ll>> v;
bool check(ll f) {
for (int i = 0; i < n; i++) {
ll x = v[i][0], a = v[i][1], b = v[i][2];
if (f < x - (i ? v[i - 1][0] : 0)) return false;
if (f <= b) f += a;
}
return (f >= d - v.back()[0]);
}
int main() {
fast_input_output();
cin >> n >> d; v.resize(n, vector<ll>(3, 0));
for (int i = 0; i < n; i++) cin >> v[i][0] >> v[i][1] >> v[i][2];
sort(v.begin(), v.end());
ll l = v.front().front(), r = 1000000000ll, mid, res = INT_MAX;
while (l <= r) {
mid = ((l + r) >> 1);
if (check(mid)) {
r = mid - 1;
res = mid;
} else l = mid + 1;
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
207 ms |
25204 KB |
Output is correct |
2 |
Correct |
219 ms |
25188 KB |
Output is correct |
3 |
Correct |
267 ms |
25176 KB |
Output is correct |
4 |
Correct |
238 ms |
25196 KB |
Output is correct |
5 |
Correct |
256 ms |
25708 KB |
Output is correct |
6 |
Correct |
190 ms |
24656 KB |
Output is correct |
7 |
Correct |
218 ms |
24548 KB |
Output is correct |
8 |
Correct |
236 ms |
25168 KB |
Output is correct |
9 |
Correct |
203 ms |
25680 KB |
Output is correct |
10 |
Correct |
240 ms |
24552 KB |
Output is correct |
11 |
Correct |
197 ms |
24552 KB |
Output is correct |
12 |
Correct |
206 ms |
25168 KB |
Output is correct |
13 |
Correct |
275 ms |
24668 KB |
Output is correct |
14 |
Correct |
222 ms |
25208 KB |
Output is correct |
15 |
Correct |
202 ms |
25188 KB |
Output is correct |
16 |
Correct |
207 ms |
25960 KB |
Output is correct |
17 |
Correct |
202 ms |
25696 KB |
Output is correct |
18 |
Correct |
240 ms |
25068 KB |
Output is correct |
19 |
Correct |
201 ms |
25172 KB |
Output is correct |
20 |
Correct |
216 ms |
25192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |