#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 |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3027 ms |
17788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
202 ms |
856 KB |
Output is correct |
3 |
Correct |
201 ms |
860 KB |
Output is correct |
4 |
Correct |
199 ms |
860 KB |
Output is correct |
5 |
Correct |
205 ms |
856 KB |
Output is correct |
6 |
Correct |
204 ms |
856 KB |
Output is correct |
7 |
Correct |
201 ms |
860 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
202 ms |
860 KB |
Output is correct |
15 |
Correct |
203 ms |
860 KB |
Output is correct |
16 |
Correct |
200 ms |
860 KB |
Output is correct |
17 |
Correct |
201 ms |
856 KB |
Output is correct |
18 |
Correct |
205 ms |
856 KB |
Output is correct |
19 |
Correct |
199 ms |
1056 KB |
Output is correct |
20 |
Correct |
96 ms |
916 KB |
Output is correct |
21 |
Correct |
95 ms |
860 KB |
Output is correct |
22 |
Correct |
205 ms |
860 KB |
Output is correct |
23 |
Correct |
203 ms |
860 KB |
Output is correct |
24 |
Correct |
207 ms |
860 KB |
Output is correct |
25 |
Correct |
204 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
202 ms |
856 KB |
Output is correct |
3 |
Correct |
201 ms |
860 KB |
Output is correct |
4 |
Correct |
199 ms |
860 KB |
Output is correct |
5 |
Correct |
205 ms |
856 KB |
Output is correct |
6 |
Correct |
204 ms |
856 KB |
Output is correct |
7 |
Correct |
201 ms |
860 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
202 ms |
860 KB |
Output is correct |
15 |
Correct |
203 ms |
860 KB |
Output is correct |
16 |
Correct |
200 ms |
860 KB |
Output is correct |
17 |
Correct |
201 ms |
856 KB |
Output is correct |
18 |
Correct |
205 ms |
856 KB |
Output is correct |
19 |
Correct |
199 ms |
1056 KB |
Output is correct |
20 |
Correct |
96 ms |
916 KB |
Output is correct |
21 |
Correct |
95 ms |
860 KB |
Output is correct |
22 |
Correct |
205 ms |
860 KB |
Output is correct |
23 |
Correct |
203 ms |
860 KB |
Output is correct |
24 |
Correct |
207 ms |
860 KB |
Output is correct |
25 |
Correct |
204 ms |
856 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Execution timed out |
3026 ms |
17656 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
202 ms |
856 KB |
Output is correct |
18 |
Correct |
201 ms |
860 KB |
Output is correct |
19 |
Correct |
199 ms |
860 KB |
Output is correct |
20 |
Correct |
205 ms |
856 KB |
Output is correct |
21 |
Correct |
204 ms |
856 KB |
Output is correct |
22 |
Correct |
201 ms |
860 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
202 ms |
860 KB |
Output is correct |
30 |
Correct |
203 ms |
860 KB |
Output is correct |
31 |
Correct |
200 ms |
860 KB |
Output is correct |
32 |
Correct |
201 ms |
856 KB |
Output is correct |
33 |
Correct |
205 ms |
856 KB |
Output is correct |
34 |
Correct |
199 ms |
1056 KB |
Output is correct |
35 |
Correct |
96 ms |
916 KB |
Output is correct |
36 |
Correct |
95 ms |
860 KB |
Output is correct |
37 |
Correct |
205 ms |
860 KB |
Output is correct |
38 |
Correct |
203 ms |
860 KB |
Output is correct |
39 |
Correct |
207 ms |
860 KB |
Output is correct |
40 |
Correct |
204 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
544 KB |
Output is correct |
42 |
Correct |
206 ms |
1112 KB |
Output is correct |
43 |
Correct |
200 ms |
860 KB |
Output is correct |
44 |
Correct |
202 ms |
916 KB |
Output is correct |
45 |
Correct |
203 ms |
860 KB |
Output is correct |
46 |
Correct |
204 ms |
860 KB |
Output is correct |
47 |
Correct |
234 ms |
860 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 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 |
203 ms |
860 KB |
Output is correct |
56 |
Correct |
205 ms |
916 KB |
Output is correct |
57 |
Correct |
219 ms |
1236 KB |
Output is correct |
58 |
Correct |
205 ms |
1196 KB |
Output is correct |
59 |
Correct |
230 ms |
1116 KB |
Output is correct |
60 |
Correct |
96 ms |
1176 KB |
Output is correct |
61 |
Correct |
100 ms |
1160 KB |
Output is correct |
62 |
Correct |
218 ms |
1176 KB |
Output is correct |
63 |
Correct |
210 ms |
1368 KB |
Output is correct |
64 |
Correct |
205 ms |
1172 KB |
Output is correct |
65 |
Correct |
209 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
16 |
Execution timed out |
3027 ms |
17788 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |