#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define intt int _; cin >> _; while (_--)
#define emp push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define ld long double
#define A first
#define B second
//#define int long long
typedef long long ll;
const ld eps = 1e-27;
// diff between decimals 0.000000001 mt19937 mt(time(nullptr));
struct in {
int a; int b; int c;
};
bool ss(in a, in b) {
return a.a<b.a;
}
int main() {
x_x
int n,d; cin>>n>>d; in ar[n]; int mn=INT_MAX;
for (auto&i:ar) cin>>i.a>>i.c>>i.b, mn=min(mn,i.b);
sort(ar, ar+n,ss);
if (n==1) {
int x=d; int y=max(ar[0].a, d-ar[0].c); if (y>ar[0].b) y=d;
cout<<min(x,y);
}
else if(mn==(1e9)) {
ll f=0, x=0; ll s=f;
for (int i=0; i<n&&ar[i].a<d; i++) {
f-=(ar[i].a-x), x=ar[i].a;
if(f<0)s+=(f*-1),f=0;
f+=ar[i].c;
}
f-=(d-x); if(f<0) s+=(f*-1);
cout<<s;
}
else if(d<=10000) {
//int ans=d;
for (int z=1; z<=d; z++) {
ll f=z, x=0; bool ok=1;
for (int i=0; i<n; i++) {
f-=(ar[i].a-x), x=ar[i].a;
if(f<0){ok=0; break;}
if (z<=ar[i].b) f+=ar[i].c;
}
if ((d-x)>f)ok=0;
if (ok) {cout<<z; break;}
}
}
else if(n<=16) {
int nm=(1<<n); ll ans=d;
for (int z=1;z<nm;++z) {
int mn=d;
for (int i=0; i<n; i++)
if (z&(1<<i))mn=min(mn,ar[i].b);
ll f=0, x=0; ll s=0; bool ok=1;
for (int i=0; i<n; i++) {
f-=(ar[i].a-x), x=ar[i].a;
if(f<0)s+=(f*-1),f=0;
if (s>mn) {ok=0; break;}
if(z&(1<<i))f+=ar[i].c;
}
if(ok)ans=min(ans,s);
}
cout<<ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
8308 KB |
Output is correct |
2 |
Correct |
92 ms |
8300 KB |
Output is correct |
3 |
Correct |
91 ms |
8300 KB |
Output is correct |
4 |
Correct |
97 ms |
8276 KB |
Output is correct |
5 |
Correct |
89 ms |
8500 KB |
Output is correct |
6 |
Correct |
89 ms |
8052 KB |
Output is correct |
7 |
Correct |
91 ms |
8048 KB |
Output is correct |
8 |
Correct |
85 ms |
8276 KB |
Output is correct |
9 |
Correct |
93 ms |
8812 KB |
Output is correct |
10 |
Correct |
84 ms |
8136 KB |
Output is correct |
11 |
Correct |
88 ms |
8044 KB |
Output is correct |
12 |
Correct |
86 ms |
8272 KB |
Output is correct |
13 |
Correct |
89 ms |
8020 KB |
Output is correct |
14 |
Correct |
94 ms |
8304 KB |
Output is correct |
15 |
Correct |
90 ms |
8304 KB |
Output is correct |
16 |
Correct |
101 ms |
8808 KB |
Output is correct |
17 |
Correct |
88 ms |
8764 KB |
Output is correct |
18 |
Correct |
95 ms |
8304 KB |
Output is correct |
19 |
Correct |
88 ms |
8172 KB |
Output is correct |
20 |
Correct |
100 ms |
8300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
680 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
12 ms |
600 KB |
Output is correct |
17 |
Correct |
21 ms |
684 KB |
Output is correct |
18 |
Correct |
31 ms |
600 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
3 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
680 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
12 ms |
600 KB |
Output is correct |
17 |
Correct |
21 ms |
684 KB |
Output is correct |
18 |
Correct |
31 ms |
600 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
3 ms |
608 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
79 ms |
6228 KB |
Output is correct |
28 |
Correct |
70 ms |
6224 KB |
Output is correct |
29 |
Correct |
69 ms |
6000 KB |
Output is correct |
30 |
Correct |
69 ms |
6252 KB |
Output is correct |
31 |
Correct |
84 ms |
6512 KB |
Output is correct |
32 |
Correct |
69 ms |
6092 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
452 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
75 ms |
6260 KB |
Output is correct |
40 |
Correct |
67 ms |
6224 KB |
Output is correct |
41 |
Correct |
99 ms |
6224 KB |
Output is correct |
42 |
Correct |
71 ms |
6224 KB |
Output is correct |
43 |
Correct |
673 ms |
6260 KB |
Output is correct |
44 |
Correct |
1080 ms |
5996 KB |
Output is correct |
45 |
Execution timed out |
3064 ms |
5980 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
9 ms |
456 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
456 KB |
Output is correct |
20 |
Correct |
4 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
344 KB |
Output is correct |
22 |
Correct |
5 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
456 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
8 ms |
456 KB |
Output is correct |
28 |
Correct |
9 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
680 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
4 ms |
604 KB |
Output is correct |
31 |
Correct |
12 ms |
600 KB |
Output is correct |
32 |
Correct |
21 ms |
684 KB |
Output is correct |
33 |
Correct |
31 ms |
600 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
3 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
3 ms |
608 KB |
Output is correct |
41 |
Correct |
0 ms |
456 KB |
Output is correct |
42 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
103 ms |
8308 KB |
Output is correct |
17 |
Correct |
92 ms |
8300 KB |
Output is correct |
18 |
Correct |
91 ms |
8300 KB |
Output is correct |
19 |
Correct |
97 ms |
8276 KB |
Output is correct |
20 |
Correct |
89 ms |
8500 KB |
Output is correct |
21 |
Correct |
89 ms |
8052 KB |
Output is correct |
22 |
Correct |
91 ms |
8048 KB |
Output is correct |
23 |
Correct |
85 ms |
8276 KB |
Output is correct |
24 |
Correct |
93 ms |
8812 KB |
Output is correct |
25 |
Correct |
84 ms |
8136 KB |
Output is correct |
26 |
Correct |
88 ms |
8044 KB |
Output is correct |
27 |
Correct |
86 ms |
8272 KB |
Output is correct |
28 |
Correct |
89 ms |
8020 KB |
Output is correct |
29 |
Correct |
94 ms |
8304 KB |
Output is correct |
30 |
Correct |
90 ms |
8304 KB |
Output is correct |
31 |
Correct |
101 ms |
8808 KB |
Output is correct |
32 |
Correct |
88 ms |
8764 KB |
Output is correct |
33 |
Correct |
95 ms |
8304 KB |
Output is correct |
34 |
Correct |
88 ms |
8172 KB |
Output is correct |
35 |
Correct |
100 ms |
8300 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
3 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
3 ms |
680 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
460 KB |
Output is correct |
49 |
Correct |
3 ms |
604 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
12 ms |
600 KB |
Output is correct |
52 |
Correct |
21 ms |
684 KB |
Output is correct |
53 |
Correct |
31 ms |
600 KB |
Output is correct |
54 |
Correct |
3 ms |
604 KB |
Output is correct |
55 |
Correct |
3 ms |
604 KB |
Output is correct |
56 |
Correct |
3 ms |
604 KB |
Output is correct |
57 |
Correct |
3 ms |
604 KB |
Output is correct |
58 |
Correct |
2 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
600 KB |
Output is correct |
60 |
Correct |
3 ms |
608 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
79 ms |
6228 KB |
Output is correct |
63 |
Correct |
70 ms |
6224 KB |
Output is correct |
64 |
Correct |
69 ms |
6000 KB |
Output is correct |
65 |
Correct |
69 ms |
6252 KB |
Output is correct |
66 |
Correct |
84 ms |
6512 KB |
Output is correct |
67 |
Correct |
69 ms |
6092 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
0 ms |
452 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
344 KB |
Output is correct |
73 |
Correct |
1 ms |
348 KB |
Output is correct |
74 |
Correct |
75 ms |
6260 KB |
Output is correct |
75 |
Correct |
67 ms |
6224 KB |
Output is correct |
76 |
Correct |
99 ms |
6224 KB |
Output is correct |
77 |
Correct |
71 ms |
6224 KB |
Output is correct |
78 |
Correct |
673 ms |
6260 KB |
Output is correct |
79 |
Correct |
1080 ms |
5996 KB |
Output is correct |
80 |
Execution timed out |
3064 ms |
5980 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |