#include <bits/stdc++.h>
using namespace std;
long long n,d;
bool check(array<long long,3>fuels[], long long f){
long long F=f;
//cout << "attempting: " << f << "\n";
for(long long i = 1;i<n+2;i++){
// cout << "at station " << i << "\n";
//cout << fuels[i][0] << " " << fuels[i][1] << " " << fuels[i][2] << "\n";
f-=fuels[i][0]-fuels[i-1][0];
// cout << "current fuel: " << f << "\n";
if(f<0){
return 0;
}
if(F>fuels[i][2]){
continue;
}
f+=fuels[i][1];
//cout << "fueled from station " << i << "\n";
}
return 1;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n>>d;
array<long long,3> fuels[n+2];
fuels[0][0]=0;
fuels[0][1]=0;
fuels[0][2]=d+5;
fuels[n+1][0]=d;
fuels[n+1][1]=0;
fuels[n+1][2]=d+5;
vector<long long>bs;
for(long long i = 1;i<=n;i++){
long long a,b,x;
cin >> x >> a >> b;
fuels[i][0]=x;
fuels[i][1]=a;
fuels[i][2]=b;
bs.push_back(b);
}
bs.push_back(d);
sort(bs.begin(),bs.end());
sort(fuels,fuels+n+2);
if(d<=1e4){
for(int i = 0;i<d;i++){
if(check(fuels,i)){
cout << i;
return 0;
}
}
}
long long hi = d;
for(long long i : bs){
if(check(fuels,i)){
hi=i;
break;
}
}
long long lo = 0;
while(lo<hi){
long long mid = (lo+hi)/2;
if(check(fuels,mid)){
hi=mid;
}
else{
lo=mid+1;
}
}
cout << lo;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
13760 KB |
Output is correct |
2 |
Correct |
110 ms |
13760 KB |
Output is correct |
3 |
Correct |
134 ms |
13756 KB |
Output is correct |
4 |
Correct |
127 ms |
13624 KB |
Output is correct |
5 |
Correct |
116 ms |
13564 KB |
Output is correct |
6 |
Correct |
114 ms |
13776 KB |
Output is correct |
7 |
Correct |
114 ms |
13760 KB |
Output is correct |
8 |
Correct |
106 ms |
13768 KB |
Output is correct |
9 |
Correct |
147 ms |
13760 KB |
Output is correct |
10 |
Correct |
111 ms |
13760 KB |
Output is correct |
11 |
Correct |
111 ms |
13716 KB |
Output is correct |
12 |
Correct |
126 ms |
13760 KB |
Output is correct |
13 |
Correct |
110 ms |
13632 KB |
Output is correct |
14 |
Correct |
112 ms |
13760 KB |
Output is correct |
15 |
Correct |
112 ms |
13732 KB |
Output is correct |
16 |
Correct |
123 ms |
13760 KB |
Output is correct |
17 |
Correct |
130 ms |
13636 KB |
Output is correct |
18 |
Correct |
111 ms |
13760 KB |
Output is correct |
19 |
Correct |
112 ms |
13780 KB |
Output is correct |
20 |
Correct |
108 ms |
13776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
848 KB |
Output is correct |
3 |
Correct |
4 ms |
848 KB |
Output is correct |
4 |
Correct |
4 ms |
848 KB |
Output is correct |
5 |
Correct |
3 ms |
848 KB |
Output is correct |
6 |
Correct |
4 ms |
900 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
16 |
Correct |
13 ms |
908 KB |
Output is correct |
17 |
Correct |
24 ms |
1020 KB |
Output is correct |
18 |
Correct |
29 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
848 KB |
Output is correct |
20 |
Correct |
4 ms |
1016 KB |
Output is correct |
21 |
Correct |
4 ms |
848 KB |
Output is correct |
22 |
Correct |
3 ms |
828 KB |
Output is correct |
23 |
Correct |
7 ms |
848 KB |
Output is correct |
24 |
Correct |
4 ms |
848 KB |
Output is correct |
25 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
848 KB |
Output is correct |
3 |
Correct |
4 ms |
848 KB |
Output is correct |
4 |
Correct |
4 ms |
848 KB |
Output is correct |
5 |
Correct |
3 ms |
848 KB |
Output is correct |
6 |
Correct |
4 ms |
900 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
16 |
Correct |
13 ms |
908 KB |
Output is correct |
17 |
Correct |
24 ms |
1020 KB |
Output is correct |
18 |
Correct |
29 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
848 KB |
Output is correct |
20 |
Correct |
4 ms |
1016 KB |
Output is correct |
21 |
Correct |
4 ms |
848 KB |
Output is correct |
22 |
Correct |
3 ms |
828 KB |
Output is correct |
23 |
Correct |
7 ms |
848 KB |
Output is correct |
24 |
Correct |
4 ms |
848 KB |
Output is correct |
25 |
Correct |
3 ms |
848 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
101 ms |
13756 KB |
Output is correct |
28 |
Correct |
107 ms |
13724 KB |
Output is correct |
29 |
Correct |
88 ms |
13760 KB |
Output is correct |
30 |
Correct |
87 ms |
13768 KB |
Output is correct |
31 |
Correct |
93 ms |
13720 KB |
Output is correct |
32 |
Correct |
96 ms |
13768 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
504 KB |
Output is correct |
39 |
Correct |
101 ms |
13772 KB |
Output is correct |
40 |
Correct |
97 ms |
13768 KB |
Output is correct |
41 |
Correct |
125 ms |
13552 KB |
Output is correct |
42 |
Correct |
98 ms |
13760 KB |
Output is correct |
43 |
Correct |
725 ms |
13760 KB |
Output is correct |
44 |
Correct |
1155 ms |
13760 KB |
Output is correct |
45 |
Execution timed out |
3054 ms |
16908 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
4 ms |
848 KB |
Output is correct |
18 |
Correct |
4 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
848 KB |
Output is correct |
20 |
Correct |
3 ms |
848 KB |
Output is correct |
21 |
Correct |
4 ms |
900 KB |
Output is correct |
22 |
Correct |
4 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
504 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
4 ms |
848 KB |
Output is correct |
30 |
Correct |
5 ms |
848 KB |
Output is correct |
31 |
Correct |
13 ms |
908 KB |
Output is correct |
32 |
Correct |
24 ms |
1020 KB |
Output is correct |
33 |
Correct |
29 ms |
848 KB |
Output is correct |
34 |
Correct |
4 ms |
848 KB |
Output is correct |
35 |
Correct |
4 ms |
1016 KB |
Output is correct |
36 |
Correct |
4 ms |
848 KB |
Output is correct |
37 |
Correct |
3 ms |
828 KB |
Output is correct |
38 |
Correct |
7 ms |
848 KB |
Output is correct |
39 |
Correct |
4 ms |
848 KB |
Output is correct |
40 |
Correct |
3 ms |
848 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
4 ms |
748 KB |
Output is correct |
43 |
Correct |
4 ms |
848 KB |
Output is correct |
44 |
Correct |
5 ms |
848 KB |
Output is correct |
45 |
Correct |
5 ms |
848 KB |
Output is correct |
46 |
Correct |
4 ms |
848 KB |
Output is correct |
47 |
Correct |
4 ms |
900 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
2 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
5 ms |
848 KB |
Output is correct |
55 |
Correct |
4 ms |
848 KB |
Output is correct |
56 |
Correct |
4 ms |
888 KB |
Output is correct |
57 |
Correct |
7 ms |
848 KB |
Output is correct |
58 |
Correct |
4 ms |
892 KB |
Output is correct |
59 |
Correct |
4 ms |
848 KB |
Output is correct |
60 |
Correct |
4 ms |
848 KB |
Output is correct |
61 |
Correct |
5 ms |
848 KB |
Output is correct |
62 |
Correct |
4 ms |
848 KB |
Output is correct |
63 |
Correct |
4 ms |
848 KB |
Output is correct |
64 |
Correct |
4 ms |
848 KB |
Output is correct |
65 |
Correct |
5 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
104 ms |
13760 KB |
Output is correct |
17 |
Correct |
110 ms |
13760 KB |
Output is correct |
18 |
Correct |
134 ms |
13756 KB |
Output is correct |
19 |
Correct |
127 ms |
13624 KB |
Output is correct |
20 |
Correct |
116 ms |
13564 KB |
Output is correct |
21 |
Correct |
114 ms |
13776 KB |
Output is correct |
22 |
Correct |
114 ms |
13760 KB |
Output is correct |
23 |
Correct |
106 ms |
13768 KB |
Output is correct |
24 |
Correct |
147 ms |
13760 KB |
Output is correct |
25 |
Correct |
111 ms |
13760 KB |
Output is correct |
26 |
Correct |
111 ms |
13716 KB |
Output is correct |
27 |
Correct |
126 ms |
13760 KB |
Output is correct |
28 |
Correct |
110 ms |
13632 KB |
Output is correct |
29 |
Correct |
112 ms |
13760 KB |
Output is correct |
30 |
Correct |
112 ms |
13732 KB |
Output is correct |
31 |
Correct |
123 ms |
13760 KB |
Output is correct |
32 |
Correct |
130 ms |
13636 KB |
Output is correct |
33 |
Correct |
111 ms |
13760 KB |
Output is correct |
34 |
Correct |
112 ms |
13780 KB |
Output is correct |
35 |
Correct |
108 ms |
13776 KB |
Output is correct |
36 |
Correct |
1 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
848 KB |
Output is correct |
38 |
Correct |
4 ms |
848 KB |
Output is correct |
39 |
Correct |
4 ms |
848 KB |
Output is correct |
40 |
Correct |
3 ms |
848 KB |
Output is correct |
41 |
Correct |
4 ms |
900 KB |
Output is correct |
42 |
Correct |
4 ms |
860 KB |
Output is correct |
43 |
Correct |
1 ms |
504 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
4 ms |
848 KB |
Output is correct |
50 |
Correct |
5 ms |
848 KB |
Output is correct |
51 |
Correct |
13 ms |
908 KB |
Output is correct |
52 |
Correct |
24 ms |
1020 KB |
Output is correct |
53 |
Correct |
29 ms |
848 KB |
Output is correct |
54 |
Correct |
4 ms |
848 KB |
Output is correct |
55 |
Correct |
4 ms |
1016 KB |
Output is correct |
56 |
Correct |
4 ms |
848 KB |
Output is correct |
57 |
Correct |
3 ms |
828 KB |
Output is correct |
58 |
Correct |
7 ms |
848 KB |
Output is correct |
59 |
Correct |
4 ms |
848 KB |
Output is correct |
60 |
Correct |
3 ms |
848 KB |
Output is correct |
61 |
Correct |
1 ms |
336 KB |
Output is correct |
62 |
Correct |
101 ms |
13756 KB |
Output is correct |
63 |
Correct |
107 ms |
13724 KB |
Output is correct |
64 |
Correct |
88 ms |
13760 KB |
Output is correct |
65 |
Correct |
87 ms |
13768 KB |
Output is correct |
66 |
Correct |
93 ms |
13720 KB |
Output is correct |
67 |
Correct |
96 ms |
13768 KB |
Output is correct |
68 |
Correct |
1 ms |
336 KB |
Output is correct |
69 |
Correct |
1 ms |
336 KB |
Output is correct |
70 |
Correct |
1 ms |
336 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
336 KB |
Output is correct |
73 |
Correct |
1 ms |
504 KB |
Output is correct |
74 |
Correct |
101 ms |
13772 KB |
Output is correct |
75 |
Correct |
97 ms |
13768 KB |
Output is correct |
76 |
Correct |
125 ms |
13552 KB |
Output is correct |
77 |
Correct |
98 ms |
13760 KB |
Output is correct |
78 |
Correct |
725 ms |
13760 KB |
Output is correct |
79 |
Correct |
1155 ms |
13760 KB |
Output is correct |
80 |
Execution timed out |
3054 ms |
16908 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |