#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define sc second
#define pb push_back
#define in insert
const ll MXT = 2000000000000;
ll dp[205][205][205][2];
int32_t main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n , l; cin>>n>>l;
ll a[n + 2],t[n + 2];
for (int i = 1; i <= n; i++)
cin>>a[i];
for (int i = 1; i <= n; i++)
cin>>t[i];
for(int i = 0; i <= n + 1; i++)
for(int j = 0; j <= n + 1; j++)
for(int k = 0; k <= n + 1; k++)
dp[i][j][k][0] = dp[i][j][k][1] = MXT;
dp[n + 1][0][0][0] = dp[n + 1][0][0][1] = 0;
a[0] = 0 ;
a[n + 1] = l;
for(int i = n + 1; i > 1; i--){
for (int j = 0; j <= i; j++) {
for(int k = 0; k <= n; k++) {
ll mn = dp[i][j][k][0] + a[j + 1] - a[j];
mn = min(mn , dp[i][j][k][1] + l - a[i] + a[j + 1]);
if (mn <= t[j + 1]) dp[i][j + 1][k + 1][0] = min(mn , dp[i][j + 1][k + 1][0]);
else dp[i][j + 1][k][0] = min(mn , dp[i][j + 1][k][0]);
mn = dp[i][j][k][0] + a[j] + l - a[i - 1];
mn = min(mn , dp[i][j][k][1] - a[i - 1] + a[i]);
if (mn <= t[i - 1]) dp[i - 1][j][k + 1][1] = min(mn , dp[i - 1][j][k + 1][1]);
else dp[i - 1][j][k][1] = min(mn , dp[i - 1][j][k][1]);
}
}
}
ll ans = 0;
for (int j = 0; j <= n; j++) {
for (ll k = 1; k <= n; k++) {
if(dp[j + 1][j][k][0] != MXT) ans = max(k, ans);
if(dp[j + 1][j][k][1] != MXT) ans = max(k, ans);
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1236 KB |
Output is correct |
30 |
Correct |
1 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
60 ms |
106064 KB |
Output is correct |
19 |
Correct |
41 ms |
64496 KB |
Output is correct |
20 |
Correct |
16 ms |
34644 KB |
Output is correct |
21 |
Correct |
30 ms |
60892 KB |
Output is correct |
22 |
Correct |
40 ms |
78932 KB |
Output is correct |
23 |
Correct |
17 ms |
29572 KB |
Output is correct |
24 |
Correct |
12 ms |
23124 KB |
Output is correct |
25 |
Correct |
15 ms |
28928 KB |
Output is correct |
26 |
Correct |
6 ms |
11220 KB |
Output is correct |
27 |
Correct |
15 ms |
30164 KB |
Output is correct |
28 |
Correct |
13 ms |
21532 KB |
Output is correct |
29 |
Correct |
14 ms |
30708 KB |
Output is correct |
30 |
Correct |
12 ms |
24200 KB |
Output is correct |
31 |
Correct |
14 ms |
28856 KB |
Output is correct |
32 |
Correct |
8 ms |
15328 KB |
Output is correct |
33 |
Correct |
15 ms |
28884 KB |
Output is correct |
34 |
Correct |
5 ms |
10496 KB |
Output is correct |
35 |
Correct |
19 ms |
28244 KB |
Output is correct |
36 |
Correct |
9 ms |
13524 KB |
Output is correct |
37 |
Correct |
16 ms |
30144 KB |
Output is correct |
38 |
Correct |
10 ms |
16636 KB |
Output is correct |
39 |
Correct |
15 ms |
31436 KB |
Output is correct |
40 |
Correct |
9 ms |
18516 KB |
Output is correct |
41 |
Correct |
68 ms |
130760 KB |
Output is correct |
42 |
Correct |
44 ms |
88268 KB |
Output is correct |
43 |
Correct |
67 ms |
130680 KB |
Output is correct |
44 |
Correct |
48 ms |
87144 KB |
Output is correct |
45 |
Correct |
84 ms |
130756 KB |
Output is correct |
46 |
Correct |
52 ms |
88268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1236 KB |
Output is correct |
30 |
Correct |
1 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
1236 KB |
Output is correct |
36 |
Correct |
60 ms |
106064 KB |
Output is correct |
37 |
Correct |
41 ms |
64496 KB |
Output is correct |
38 |
Correct |
16 ms |
34644 KB |
Output is correct |
39 |
Correct |
30 ms |
60892 KB |
Output is correct |
40 |
Correct |
40 ms |
78932 KB |
Output is correct |
41 |
Correct |
17 ms |
29572 KB |
Output is correct |
42 |
Correct |
12 ms |
23124 KB |
Output is correct |
43 |
Correct |
15 ms |
28928 KB |
Output is correct |
44 |
Correct |
6 ms |
11220 KB |
Output is correct |
45 |
Correct |
15 ms |
30164 KB |
Output is correct |
46 |
Correct |
13 ms |
21532 KB |
Output is correct |
47 |
Correct |
14 ms |
30708 KB |
Output is correct |
48 |
Correct |
12 ms |
24200 KB |
Output is correct |
49 |
Correct |
14 ms |
28856 KB |
Output is correct |
50 |
Correct |
8 ms |
15328 KB |
Output is correct |
51 |
Correct |
15 ms |
28884 KB |
Output is correct |
52 |
Correct |
5 ms |
10496 KB |
Output is correct |
53 |
Correct |
19 ms |
28244 KB |
Output is correct |
54 |
Correct |
9 ms |
13524 KB |
Output is correct |
55 |
Correct |
16 ms |
30144 KB |
Output is correct |
56 |
Correct |
10 ms |
16636 KB |
Output is correct |
57 |
Correct |
15 ms |
31436 KB |
Output is correct |
58 |
Correct |
9 ms |
18516 KB |
Output is correct |
59 |
Correct |
68 ms |
130760 KB |
Output is correct |
60 |
Correct |
44 ms |
88268 KB |
Output is correct |
61 |
Correct |
67 ms |
130680 KB |
Output is correct |
62 |
Correct |
48 ms |
87144 KB |
Output is correct |
63 |
Correct |
84 ms |
130756 KB |
Output is correct |
64 |
Correct |
52 ms |
88268 KB |
Output is correct |
65 |
Correct |
70 ms |
118048 KB |
Output is correct |
66 |
Correct |
58 ms |
108452 KB |
Output is correct |
67 |
Correct |
56 ms |
103808 KB |
Output is correct |
68 |
Correct |
58 ms |
95888 KB |
Output is correct |
69 |
Correct |
66 ms |
116800 KB |
Output is correct |
70 |
Correct |
64 ms |
112044 KB |
Output is correct |
71 |
Correct |
63 ms |
113260 KB |
Output is correct |
72 |
Correct |
62 ms |
114408 KB |
Output is correct |
73 |
Correct |
60 ms |
106124 KB |
Output is correct |
74 |
Correct |
52 ms |
99116 KB |
Output is correct |
75 |
Correct |
63 ms |
109648 KB |
Output is correct |
76 |
Correct |
69 ms |
125524 KB |
Output is correct |
77 |
Correct |
68 ms |
125636 KB |
Output is correct |
78 |
Correct |
56 ms |
97080 KB |
Output is correct |
79 |
Correct |
57 ms |
100372 KB |
Output is correct |
80 |
Correct |
84 ms |
123100 KB |
Output is correct |
81 |
Correct |
53 ms |
101412 KB |
Output is correct |
82 |
Correct |
55 ms |
107280 KB |
Output is correct |
83 |
Correct |
72 ms |
130664 KB |
Output is correct |
84 |
Correct |
61 ms |
112052 KB |
Output is correct |
85 |
Correct |
64 ms |
121804 KB |
Output is correct |
86 |
Correct |
76 ms |
119248 KB |
Output is correct |
87 |
Correct |
78 ms |
109652 KB |
Output is correct |
88 |
Correct |
81 ms |
131968 KB |
Output is correct |
89 |
Correct |
68 ms |
132040 KB |
Output is correct |
90 |
Correct |
59 ms |
110768 KB |
Output is correct |
91 |
Correct |
71 ms |
132068 KB |
Output is correct |
92 |
Correct |
80 ms |
132064 KB |
Output is correct |
93 |
Correct |
82 ms |
129388 KB |
Output is correct |