#include <bits/stdc++.h>
using namespace std;
struct stamps{
long long d,t;
}a[205];
long long dp[205][205][205][5],n,l,ans;
int main(){
ios::sync_with_stdio(false);
cin >> n >> l;
for (int i=1;i<=n;i++){
cin >> a[i].d;
}
for (int i=1;i<=n;i++){
cin >> a[i].t;
}
for (int i=0;i<=n+1;i++){
for (int j=0;j<=n+1;j++){
for (int k=0;k<=n;k++){
dp[i][j][k][0]=dp[i][j][k][1]=1e18;
}
}
}
a[n+1].d=l;
dp[0][n+1][0][0]=dp[0][n+1][0][1]=0;
for (int i=0;i<=n;i++){
for (int j=n+1;j>i;j--){
for (int k=0;k<=max(0LL,n-j+1)+i;k++){
if (i != 0){
if (k > 0 && dp[i-1][j][k-1][0]+a[i].d-a[i-1].d <= a[i].t)
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k-1][0]+a[i].d-a[i-1].d);
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k][0]+a[i].d-a[i-1].d);
if (k > 0 && j != n+1 && dp[i-1][j][k-1][1]+l-a[j].d+a[i].d <= a[i].t)
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k-1][1]+l-a[j].d+a[i].d);
if (j != n+1)
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k][1]+l-a[j].d+a[i].d);
}
if (j != n+1){
if (k > 0 && dp[i][j+1][k-1][1]+a[j+1].d-a[j].d <= a[j].t)
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j+1][k-1][1]+a[j+1].d-a[j].d);
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j+1][k][1]+a[j+1].d-a[j].d);
// cout << i << " " << j << " " << k << " " << dp[i][j+1][k-1][1] << " " << a[j+1].d<< " " << a[j].d << " " << l-a[j+1].d+a[j].d << "\n";
if (k > 0 && i != 0 && dp[i][j+1][k-1][0]+l-a[j].d+a[i].d <= a[j].t)
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j+1][k-1][0]+l-a[j].d+a[i].d);
if (i != 0)
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j+1][k][0]+l-a[j].d+a[i].d);
}
}
}
}
for (int i=0;i<=n;i++){
for (int j=n+1;j>i;j--){
if (i+1 == j){
for (long long k=1;k<=n;k++){
if (dp[i][j][k][0] != 1e18 || dp[i][j][k][1] != 1e18)
ans=max(ans,k);
}
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
720 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
720 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1088 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
1100 KB |
Output is correct |
21 |
Correct |
2 ms |
1356 KB |
Output is correct |
22 |
Correct |
1 ms |
896 KB |
Output is correct |
23 |
Correct |
1 ms |
1484 KB |
Output is correct |
24 |
Correct |
1 ms |
1228 KB |
Output is correct |
25 |
Correct |
1 ms |
1356 KB |
Output is correct |
26 |
Correct |
1 ms |
1356 KB |
Output is correct |
27 |
Correct |
1 ms |
716 KB |
Output is correct |
28 |
Correct |
1 ms |
840 KB |
Output is correct |
29 |
Correct |
2 ms |
1488 KB |
Output is correct |
30 |
Correct |
1 ms |
1480 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1228 KB |
Output is correct |
33 |
Correct |
1 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1484 KB |
Output is correct |
35 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
720 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1088 KB |
Output is correct |
18 |
Correct |
140 ms |
263680 KB |
Output is correct |
19 |
Correct |
85 ms |
160164 KB |
Output is correct |
20 |
Correct |
44 ms |
84896 KB |
Output is correct |
21 |
Correct |
75 ms |
151120 KB |
Output is correct |
22 |
Correct |
97 ms |
195944 KB |
Output is correct |
23 |
Correct |
34 ms |
69932 KB |
Output is correct |
24 |
Correct |
26 ms |
51620 KB |
Output is correct |
25 |
Correct |
33 ms |
68176 KB |
Output is correct |
26 |
Correct |
11 ms |
21328 KB |
Output is correct |
27 |
Correct |
37 ms |
71712 KB |
Output is correct |
28 |
Correct |
25 ms |
47676 KB |
Output is correct |
29 |
Correct |
42 ms |
73476 KB |
Output is correct |
30 |
Correct |
26 ms |
54512 KB |
Output is correct |
31 |
Correct |
38 ms |
68132 KB |
Output is correct |
32 |
Correct |
15 ms |
30284 KB |
Output is correct |
33 |
Correct |
34 ms |
68204 KB |
Output is correct |
34 |
Correct |
10 ms |
19532 KB |
Output is correct |
35 |
Correct |
31 ms |
66380 KB |
Output is correct |
36 |
Correct |
13 ms |
26812 KB |
Output is correct |
37 |
Correct |
36 ms |
71736 KB |
Output is correct |
38 |
Correct |
17 ms |
34108 KB |
Output is correct |
39 |
Correct |
35 ms |
75372 KB |
Output is correct |
40 |
Correct |
20 ms |
39268 KB |
Output is correct |
41 |
Correct |
166 ms |
325180 KB |
Output is correct |
42 |
Correct |
112 ms |
219060 KB |
Output is correct |
43 |
Correct |
173 ms |
325148 KB |
Output is correct |
44 |
Correct |
125 ms |
216432 KB |
Output is correct |
45 |
Correct |
170 ms |
325140 KB |
Output is correct |
46 |
Correct |
111 ms |
219052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
720 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1088 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
1100 KB |
Output is correct |
21 |
Correct |
2 ms |
1356 KB |
Output is correct |
22 |
Correct |
1 ms |
896 KB |
Output is correct |
23 |
Correct |
1 ms |
1484 KB |
Output is correct |
24 |
Correct |
1 ms |
1228 KB |
Output is correct |
25 |
Correct |
1 ms |
1356 KB |
Output is correct |
26 |
Correct |
1 ms |
1356 KB |
Output is correct |
27 |
Correct |
1 ms |
716 KB |
Output is correct |
28 |
Correct |
1 ms |
840 KB |
Output is correct |
29 |
Correct |
2 ms |
1488 KB |
Output is correct |
30 |
Correct |
1 ms |
1480 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1228 KB |
Output is correct |
33 |
Correct |
1 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1484 KB |
Output is correct |
35 |
Correct |
1 ms |
1484 KB |
Output is correct |
36 |
Correct |
140 ms |
263680 KB |
Output is correct |
37 |
Correct |
85 ms |
160164 KB |
Output is correct |
38 |
Correct |
44 ms |
84896 KB |
Output is correct |
39 |
Correct |
75 ms |
151120 KB |
Output is correct |
40 |
Correct |
97 ms |
195944 KB |
Output is correct |
41 |
Correct |
34 ms |
69932 KB |
Output is correct |
42 |
Correct |
26 ms |
51620 KB |
Output is correct |
43 |
Correct |
33 ms |
68176 KB |
Output is correct |
44 |
Correct |
11 ms |
21328 KB |
Output is correct |
45 |
Correct |
37 ms |
71712 KB |
Output is correct |
46 |
Correct |
25 ms |
47676 KB |
Output is correct |
47 |
Correct |
42 ms |
73476 KB |
Output is correct |
48 |
Correct |
26 ms |
54512 KB |
Output is correct |
49 |
Correct |
38 ms |
68132 KB |
Output is correct |
50 |
Correct |
15 ms |
30284 KB |
Output is correct |
51 |
Correct |
34 ms |
68204 KB |
Output is correct |
52 |
Correct |
10 ms |
19532 KB |
Output is correct |
53 |
Correct |
31 ms |
66380 KB |
Output is correct |
54 |
Correct |
13 ms |
26812 KB |
Output is correct |
55 |
Correct |
36 ms |
71736 KB |
Output is correct |
56 |
Correct |
17 ms |
34108 KB |
Output is correct |
57 |
Correct |
35 ms |
75372 KB |
Output is correct |
58 |
Correct |
20 ms |
39268 KB |
Output is correct |
59 |
Correct |
166 ms |
325180 KB |
Output is correct |
60 |
Correct |
112 ms |
219060 KB |
Output is correct |
61 |
Correct |
173 ms |
325148 KB |
Output is correct |
62 |
Correct |
125 ms |
216432 KB |
Output is correct |
63 |
Correct |
170 ms |
325140 KB |
Output is correct |
64 |
Correct |
111 ms |
219052 KB |
Output is correct |
65 |
Correct |
152 ms |
293664 KB |
Output is correct |
66 |
Correct |
136 ms |
269512 KB |
Output is correct |
67 |
Correct |
133 ms |
257808 KB |
Output is correct |
68 |
Correct |
124 ms |
238216 KB |
Output is correct |
69 |
Correct |
152 ms |
290548 KB |
Output is correct |
70 |
Correct |
144 ms |
278440 KB |
Output is correct |
71 |
Correct |
146 ms |
281528 KB |
Output is correct |
72 |
Correct |
153 ms |
284484 KB |
Output is correct |
73 |
Correct |
131 ms |
263620 KB |
Output is correct |
74 |
Correct |
123 ms |
246468 KB |
Output is correct |
75 |
Correct |
136 ms |
272408 KB |
Output is correct |
76 |
Correct |
166 ms |
312360 KB |
Output is correct |
77 |
Correct |
155 ms |
312308 KB |
Output is correct |
78 |
Correct |
120 ms |
240888 KB |
Output is correct |
79 |
Correct |
123 ms |
249380 KB |
Output is correct |
80 |
Correct |
161 ms |
305988 KB |
Output is correct |
81 |
Correct |
127 ms |
252188 KB |
Output is correct |
82 |
Correct |
138 ms |
266608 KB |
Output is correct |
83 |
Correct |
164 ms |
325144 KB |
Output is correct |
84 |
Correct |
140 ms |
278596 KB |
Output is correct |
85 |
Correct |
155 ms |
302952 KB |
Output is correct |
86 |
Correct |
167 ms |
296668 KB |
Output is correct |
87 |
Correct |
149 ms |
272476 KB |
Output is correct |
88 |
Correct |
170 ms |
328388 KB |
Output is correct |
89 |
Correct |
167 ms |
328424 KB |
Output is correct |
90 |
Correct |
139 ms |
275628 KB |
Output is correct |
91 |
Correct |
188 ms |
328644 KB |
Output is correct |
92 |
Correct |
173 ms |
328396 KB |
Output is correct |
93 |
Correct |
160 ms |
321860 KB |
Output is correct |