#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll dp[205][205][2][205];
const ll INF = 1e15;
ll a[205];
ll b[205];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
ll n, l;
cin >> n >> l;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=n; i++){
cin >> b[i];
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int k=0; k<=1; k++){
for(int r=0; r<=n; r++){
dp[i][j][k][r] = INF;
}
}
}
}
dp[1][1][1][(b[1] >= a[1])] = a[1];
dp[n][n][0][(b[n] >= l-a[n])] = l-a[n];
for(int len=1; len<n; len++){
for(int i=n; i>=1; i--){
int ost = len-(n-i+1);
if(ost <= 0) break;
int j = ost;
for(int k=0; k<=n; k++){
ll vreme = dp[i][j][0][k];
int novi = (vreme+a[i]-a[i-1] <= b[i-1]) + k;
dp[i-1][j][0][novi] = min(dp[i-1][j][0][novi], vreme+a[i]-a[i-1]);
novi = (vreme+l-a[i]+a[j+1] <= b[j+1]) + k;
dp[i][j+1][1][novi] = min(dp[i][j+1][1][novi], vreme+l-a[i]+a[j+1]);
vreme = dp[i][j][1][k];
novi = (vreme+a[j+1]-a[j] <= b[j+1]) + k;
dp[i][j+1][1][novi] = min(dp[i][j+1][1][novi], vreme+a[j+1]-a[j]);
novi = (vreme+l-a[i-1]+a[j] <= b[i-1]) + k;
dp[i-1][j][0][novi] = min(dp[i-1][j][0][novi], vreme+l-a[i-1]+a[j]);
}
}
for(int k=0; k<=n; k++){
ll vreme = dp[1][len][1][k];
int novi = (vreme+a[len+1]-a[len] <= b[len+1]) + k;
dp[1][len+1][1][novi] = min(dp[1][len+1][1][novi], vreme+a[len+1]-a[len]);
novi = (vreme+l-a[n]+a[len] <= b[n]) + k;
dp[n][len][0][novi] = min(dp[n][len][0][novi], vreme+l-a[n]+a[len]);
int j = n-len+1;
vreme = dp[j][n][0][k];
novi = (vreme+a[j]-a[j-1] <= b[j-1]) + k;
dp[j-1][n][0][novi] = min(dp[j-1][n][0][novi], vreme+a[j]-a[j-1]);
novi = (vreme+a[1]+l-a[j] <= b[1]) + k;
dp[j][1][1][novi] = min(dp[j][1][1][novi], vreme+a[1]+l-a[j]);
}
}
//cout << dp[5][5][0][1] << endl;
int res = 0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int k=0; k<=1; k++){
for(int r=0; r<=n; r++){
if(dp[i][j][k][r] != INF) res = max(res, r);
//if(r == 5 && dp[i][j][k][r] != INF) cout << i << " " << j << " " << k << " " << dp[i][j][k][r] << endl;
}
}
}
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
1024 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
5 ms |
1024 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
1152 KB |
Output is correct |
24 |
Correct |
5 ms |
896 KB |
Output is correct |
25 |
Correct |
5 ms |
1024 KB |
Output is correct |
26 |
Correct |
5 ms |
1024 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
640 KB |
Output is correct |
29 |
Correct |
6 ms |
1152 KB |
Output is correct |
30 |
Correct |
5 ms |
1152 KB |
Output is correct |
31 |
Correct |
5 ms |
1024 KB |
Output is correct |
32 |
Correct |
5 ms |
896 KB |
Output is correct |
33 |
Correct |
5 ms |
1152 KB |
Output is correct |
34 |
Correct |
6 ms |
1152 KB |
Output is correct |
35 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
117 ms |
103928 KB |
Output is correct |
19 |
Correct |
66 ms |
62848 KB |
Output is correct |
20 |
Correct |
37 ms |
33408 KB |
Output is correct |
21 |
Correct |
66 ms |
59408 KB |
Output is correct |
22 |
Correct |
87 ms |
77048 KB |
Output is correct |
23 |
Correct |
32 ms |
28416 KB |
Output is correct |
24 |
Correct |
25 ms |
22272 KB |
Output is correct |
25 |
Correct |
33 ms |
27904 KB |
Output is correct |
26 |
Correct |
13 ms |
10624 KB |
Output is correct |
27 |
Correct |
33 ms |
29056 KB |
Output is correct |
28 |
Correct |
23 ms |
20736 KB |
Output is correct |
29 |
Correct |
33 ms |
29696 KB |
Output is correct |
30 |
Correct |
27 ms |
23296 KB |
Output is correct |
31 |
Correct |
32 ms |
27904 KB |
Output is correct |
32 |
Correct |
17 ms |
14592 KB |
Output is correct |
33 |
Correct |
31 ms |
27904 KB |
Output is correct |
34 |
Correct |
12 ms |
9856 KB |
Output is correct |
35 |
Correct |
31 ms |
27264 KB |
Output is correct |
36 |
Correct |
15 ms |
12928 KB |
Output is correct |
37 |
Correct |
34 ms |
29108 KB |
Output is correct |
38 |
Correct |
19 ms |
15872 KB |
Output is correct |
39 |
Correct |
33 ms |
30336 KB |
Output is correct |
40 |
Correct |
20 ms |
17664 KB |
Output is correct |
41 |
Correct |
149 ms |
128248 KB |
Output is correct |
42 |
Correct |
96 ms |
86264 KB |
Output is correct |
43 |
Correct |
157 ms |
128376 KB |
Output is correct |
44 |
Correct |
92 ms |
85240 KB |
Output is correct |
45 |
Correct |
155 ms |
128248 KB |
Output is correct |
46 |
Correct |
97 ms |
86264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
1024 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
5 ms |
1024 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
1152 KB |
Output is correct |
24 |
Correct |
5 ms |
896 KB |
Output is correct |
25 |
Correct |
5 ms |
1024 KB |
Output is correct |
26 |
Correct |
5 ms |
1024 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
640 KB |
Output is correct |
29 |
Correct |
6 ms |
1152 KB |
Output is correct |
30 |
Correct |
5 ms |
1152 KB |
Output is correct |
31 |
Correct |
5 ms |
1024 KB |
Output is correct |
32 |
Correct |
5 ms |
896 KB |
Output is correct |
33 |
Correct |
5 ms |
1152 KB |
Output is correct |
34 |
Correct |
6 ms |
1152 KB |
Output is correct |
35 |
Correct |
5 ms |
1152 KB |
Output is correct |
36 |
Correct |
117 ms |
103928 KB |
Output is correct |
37 |
Correct |
66 ms |
62848 KB |
Output is correct |
38 |
Correct |
37 ms |
33408 KB |
Output is correct |
39 |
Correct |
66 ms |
59408 KB |
Output is correct |
40 |
Correct |
87 ms |
77048 KB |
Output is correct |
41 |
Correct |
32 ms |
28416 KB |
Output is correct |
42 |
Correct |
25 ms |
22272 KB |
Output is correct |
43 |
Correct |
33 ms |
27904 KB |
Output is correct |
44 |
Correct |
13 ms |
10624 KB |
Output is correct |
45 |
Correct |
33 ms |
29056 KB |
Output is correct |
46 |
Correct |
23 ms |
20736 KB |
Output is correct |
47 |
Correct |
33 ms |
29696 KB |
Output is correct |
48 |
Correct |
27 ms |
23296 KB |
Output is correct |
49 |
Correct |
32 ms |
27904 KB |
Output is correct |
50 |
Correct |
17 ms |
14592 KB |
Output is correct |
51 |
Correct |
31 ms |
27904 KB |
Output is correct |
52 |
Correct |
12 ms |
9856 KB |
Output is correct |
53 |
Correct |
31 ms |
27264 KB |
Output is correct |
54 |
Correct |
15 ms |
12928 KB |
Output is correct |
55 |
Correct |
34 ms |
29108 KB |
Output is correct |
56 |
Correct |
19 ms |
15872 KB |
Output is correct |
57 |
Correct |
33 ms |
30336 KB |
Output is correct |
58 |
Correct |
20 ms |
17664 KB |
Output is correct |
59 |
Correct |
149 ms |
128248 KB |
Output is correct |
60 |
Correct |
96 ms |
86264 KB |
Output is correct |
61 |
Correct |
157 ms |
128376 KB |
Output is correct |
62 |
Correct |
92 ms |
85240 KB |
Output is correct |
63 |
Correct |
155 ms |
128248 KB |
Output is correct |
64 |
Correct |
97 ms |
86264 KB |
Output is correct |
65 |
Correct |
134 ms |
115832 KB |
Output is correct |
66 |
Correct |
122 ms |
106252 KB |
Output is correct |
67 |
Correct |
117 ms |
101608 KB |
Output is correct |
68 |
Correct |
107 ms |
93688 KB |
Output is correct |
69 |
Correct |
133 ms |
114656 KB |
Output is correct |
70 |
Correct |
126 ms |
109684 KB |
Output is correct |
71 |
Correct |
128 ms |
110968 KB |
Output is correct |
72 |
Correct |
132 ms |
112120 KB |
Output is correct |
73 |
Correct |
118 ms |
103960 KB |
Output is correct |
74 |
Correct |
112 ms |
97016 KB |
Output is correct |
75 |
Correct |
120 ms |
107384 KB |
Output is correct |
76 |
Correct |
141 ms |
123128 KB |
Output is correct |
77 |
Correct |
145 ms |
123324 KB |
Output is correct |
78 |
Correct |
109 ms |
94840 KB |
Output is correct |
79 |
Correct |
109 ms |
98168 KB |
Output is correct |
80 |
Correct |
143 ms |
120700 KB |
Output is correct |
81 |
Correct |
115 ms |
99324 KB |
Output is correct |
82 |
Correct |
118 ms |
105080 KB |
Output is correct |
83 |
Correct |
153 ms |
128248 KB |
Output is correct |
84 |
Correct |
126 ms |
109688 KB |
Output is correct |
85 |
Correct |
141 ms |
119584 KB |
Output is correct |
86 |
Correct |
136 ms |
116984 KB |
Output is correct |
87 |
Correct |
132 ms |
107384 KB |
Output is correct |
88 |
Correct |
152 ms |
129528 KB |
Output is correct |
89 |
Correct |
158 ms |
129784 KB |
Output is correct |
90 |
Correct |
132 ms |
108536 KB |
Output is correct |
91 |
Correct |
151 ms |
129568 KB |
Output is correct |
92 |
Correct |
152 ms |
129664 KB |
Output is correct |
93 |
Correct |
151 ms |
127140 KB |
Output is correct |