#include <bits/stdc++.h>
using namespace std;
#define int long long
void doWork(){
int N , D;
cin >> N >> D;
vector<array<int, 3>> v;
vector<int> B;
for (int i = 0 ; i < N ; i++){
int x , a , b ;
cin >> x >> a >> b;
v.push_back({x , a , b});
B.push_back(b);
}
B.push_back(1e18);
v.push_back({D , 0 , 0});
sort(v.begin() , v.end());
sort(B.begin() , B.end());
int ans = 1e18;
for (int F = 0 ; F <= N ; F++){
int mn = 1e18;
int sum = B[F];
for (int i = 0 ; i <= N ; i++){
mn = min(mn , sum - v[i][0]);
if (B[F] <= v[i][2]) sum += v[i][1];
}
if (mn >= 0) ans = min(ans , B[F] - mn);
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
doWork();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3059 ms |
18228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
201 ms |
860 KB |
Output is correct |
3 |
Correct |
215 ms |
1172 KB |
Output is correct |
4 |
Correct |
206 ms |
860 KB |
Output is correct |
5 |
Correct |
204 ms |
860 KB |
Output is correct |
6 |
Correct |
202 ms |
860 KB |
Output is correct |
7 |
Correct |
200 ms |
856 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
203 ms |
860 KB |
Output is correct |
15 |
Correct |
230 ms |
860 KB |
Output is correct |
16 |
Correct |
203 ms |
860 KB |
Output is correct |
17 |
Correct |
220 ms |
860 KB |
Output is correct |
18 |
Correct |
209 ms |
1112 KB |
Output is correct |
19 |
Correct |
203 ms |
860 KB |
Output is correct |
20 |
Correct |
98 ms |
864 KB |
Output is correct |
21 |
Correct |
99 ms |
860 KB |
Output is correct |
22 |
Correct |
204 ms |
860 KB |
Output is correct |
23 |
Correct |
204 ms |
860 KB |
Output is correct |
24 |
Correct |
200 ms |
856 KB |
Output is correct |
25 |
Correct |
205 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
201 ms |
860 KB |
Output is correct |
3 |
Correct |
215 ms |
1172 KB |
Output is correct |
4 |
Correct |
206 ms |
860 KB |
Output is correct |
5 |
Correct |
204 ms |
860 KB |
Output is correct |
6 |
Correct |
202 ms |
860 KB |
Output is correct |
7 |
Correct |
200 ms |
856 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
203 ms |
860 KB |
Output is correct |
15 |
Correct |
230 ms |
860 KB |
Output is correct |
16 |
Correct |
203 ms |
860 KB |
Output is correct |
17 |
Correct |
220 ms |
860 KB |
Output is correct |
18 |
Correct |
209 ms |
1112 KB |
Output is correct |
19 |
Correct |
203 ms |
860 KB |
Output is correct |
20 |
Correct |
98 ms |
864 KB |
Output is correct |
21 |
Correct |
99 ms |
860 KB |
Output is correct |
22 |
Correct |
204 ms |
860 KB |
Output is correct |
23 |
Correct |
204 ms |
860 KB |
Output is correct |
24 |
Correct |
200 ms |
856 KB |
Output is correct |
25 |
Correct |
205 ms |
860 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
3085 ms |
17176 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
412 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
201 ms |
860 KB |
Output is correct |
18 |
Correct |
215 ms |
1172 KB |
Output is correct |
19 |
Correct |
206 ms |
860 KB |
Output is correct |
20 |
Correct |
204 ms |
860 KB |
Output is correct |
21 |
Correct |
202 ms |
860 KB |
Output is correct |
22 |
Correct |
200 ms |
856 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
203 ms |
860 KB |
Output is correct |
30 |
Correct |
230 ms |
860 KB |
Output is correct |
31 |
Correct |
203 ms |
860 KB |
Output is correct |
32 |
Correct |
220 ms |
860 KB |
Output is correct |
33 |
Correct |
209 ms |
1112 KB |
Output is correct |
34 |
Correct |
203 ms |
860 KB |
Output is correct |
35 |
Correct |
98 ms |
864 KB |
Output is correct |
36 |
Correct |
99 ms |
860 KB |
Output is correct |
37 |
Correct |
204 ms |
860 KB |
Output is correct |
38 |
Correct |
204 ms |
860 KB |
Output is correct |
39 |
Correct |
200 ms |
856 KB |
Output is correct |
40 |
Correct |
205 ms |
860 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
210 ms |
920 KB |
Output is correct |
43 |
Correct |
200 ms |
916 KB |
Output is correct |
44 |
Correct |
199 ms |
856 KB |
Output is correct |
45 |
Correct |
202 ms |
860 KB |
Output is correct |
46 |
Correct |
201 ms |
856 KB |
Output is correct |
47 |
Correct |
202 ms |
856 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
202 ms |
860 KB |
Output is correct |
55 |
Correct |
201 ms |
856 KB |
Output is correct |
56 |
Correct |
201 ms |
860 KB |
Output is correct |
57 |
Correct |
200 ms |
860 KB |
Output is correct |
58 |
Correct |
203 ms |
856 KB |
Output is correct |
59 |
Correct |
204 ms |
916 KB |
Output is correct |
60 |
Correct |
96 ms |
916 KB |
Output is correct |
61 |
Correct |
96 ms |
856 KB |
Output is correct |
62 |
Correct |
209 ms |
860 KB |
Output is correct |
63 |
Correct |
205 ms |
860 KB |
Output is correct |
64 |
Correct |
203 ms |
856 KB |
Output is correct |
65 |
Correct |
211 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Execution timed out |
3059 ms |
18228 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |