#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2+10;
typedef long long ll;
const ll inf = 1e9;
ll dp[maxn][maxn][maxn][2], x[maxn], t[maxn];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll n, l;
cin >> n >> l;
for(int i=1; i<=n; i++) cin >> x[i];
for(int i=1; i<=n; i++) cin >> t[i];
for(int i=0; i<=n; i++){
for(int j=0; j<=n; j++){
for(int k=0; k<=n; k++){
dp[i][j][k][0] = dp[i][j][k][1] = inf;
}
}
}
dp[0][0][0][0] = dp[0][0][0][1] = 0;
auto prv = [&](ll x){
if(x-1 < 1) return n;
return x-1;
};
auto nxt = [&](ll x){
if(x+1 > n) return 1LL;
return x+1;
};
auto d = [&](ll a, ll b){
if(a > b) swap(a, b);
return min(x[b] - x[a], l - x[b] + x[a]);
};
auto min_self = [&](ll &a, ll &b){
a = min(a, b);
};
for(ll len=0; len<n; len++){
for(ll i=0; i<=n; i++){
for(ll k=0; k<=len; k++){
ll j = (i + len)%(n+1);
//l -> l
ll tt = dp[i][j][k][0] + d(prv(i), i);
min_self(dp[prv(i)][j][k+(tt <= t[prv(i)])][0], tt);
//r -> l
tt = dp[i][j][k][1] + d(prv(i), j);
min_self(dp[prv(i)][j][k+(tt <= t[prv(i)])][0], tt);
//l -> r
tt = dp[i][j][k][0] + d(i, nxt(j));
min_self(dp[i][nxt(j)][k+(tt <= t[nxt(j)])][1], tt);
//r -> r
tt = dp[i][j][k][1] + d(j, nxt(j));
min_self(dp[i][nxt(j)][k+(tt <= t[nxt(j)])][1], tt);
}
}
}
ll ans = 0;
for(ll i=0; i<=n; i++){
for(ll j=0; j<=n; j++){
for(ll k=0; k<=n; k++){
for(int q : {0, 1}){
if(dp[i][j][k][q] != inf) ans = max(ans, k);
}
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
656 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
908 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
1 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
656 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
908 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
1 ms |
876 KB |
Output is correct |
18 |
Correct |
1 ms |
1132 KB |
Output is correct |
19 |
Correct |
1 ms |
748 KB |
Output is correct |
20 |
Correct |
1 ms |
876 KB |
Output is correct |
21 |
Correct |
1 ms |
1132 KB |
Output is correct |
22 |
Correct |
1 ms |
620 KB |
Output is correct |
23 |
Correct |
1 ms |
1260 KB |
Output is correct |
24 |
Correct |
1 ms |
1004 KB |
Output is correct |
25 |
Correct |
1 ms |
1132 KB |
Output is correct |
26 |
Correct |
1 ms |
1132 KB |
Output is correct |
27 |
Correct |
1 ms |
620 KB |
Output is correct |
28 |
Correct |
1 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
1260 KB |
Output is correct |
30 |
Correct |
1 ms |
1260 KB |
Output is correct |
31 |
Correct |
1 ms |
1132 KB |
Output is correct |
32 |
Correct |
1 ms |
1004 KB |
Output is correct |
33 |
Correct |
1 ms |
1260 KB |
Output is correct |
34 |
Correct |
1 ms |
1260 KB |
Output is correct |
35 |
Correct |
1 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
656 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
908 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
1 ms |
876 KB |
Output is correct |
18 |
Correct |
141 ms |
107500 KB |
Output is correct |
19 |
Correct |
84 ms |
65260 KB |
Output is correct |
20 |
Correct |
34 ms |
34796 KB |
Output is correct |
21 |
Correct |
70 ms |
61696 KB |
Output is correct |
22 |
Correct |
97 ms |
79980 KB |
Output is correct |
23 |
Correct |
29 ms |
29676 KB |
Output is correct |
24 |
Correct |
22 ms |
23276 KB |
Output is correct |
25 |
Correct |
28 ms |
29036 KB |
Output is correct |
26 |
Correct |
10 ms |
11116 KB |
Output is correct |
27 |
Correct |
30 ms |
30316 KB |
Output is correct |
28 |
Correct |
20 ms |
21612 KB |
Output is correct |
29 |
Correct |
35 ms |
30956 KB |
Output is correct |
30 |
Correct |
26 ms |
24448 KB |
Output is correct |
31 |
Correct |
28 ms |
29164 KB |
Output is correct |
32 |
Correct |
13 ms |
15212 KB |
Output is correct |
33 |
Correct |
33 ms |
29036 KB |
Output is correct |
34 |
Correct |
8 ms |
10476 KB |
Output is correct |
35 |
Correct |
28 ms |
28396 KB |
Output is correct |
36 |
Correct |
11 ms |
13548 KB |
Output is correct |
37 |
Correct |
30 ms |
30336 KB |
Output is correct |
38 |
Correct |
14 ms |
16620 KB |
Output is correct |
39 |
Correct |
31 ms |
31596 KB |
Output is correct |
40 |
Correct |
16 ms |
18540 KB |
Output is correct |
41 |
Correct |
167 ms |
132644 KB |
Output is correct |
42 |
Correct |
109 ms |
89452 KB |
Output is correct |
43 |
Correct |
184 ms |
132588 KB |
Output is correct |
44 |
Correct |
109 ms |
88300 KB |
Output is correct |
45 |
Correct |
178 ms |
132588 KB |
Output is correct |
46 |
Correct |
110 ms |
89324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
656 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
908 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
1 ms |
876 KB |
Output is correct |
18 |
Correct |
1 ms |
1132 KB |
Output is correct |
19 |
Correct |
1 ms |
748 KB |
Output is correct |
20 |
Correct |
1 ms |
876 KB |
Output is correct |
21 |
Correct |
1 ms |
1132 KB |
Output is correct |
22 |
Correct |
1 ms |
620 KB |
Output is correct |
23 |
Correct |
1 ms |
1260 KB |
Output is correct |
24 |
Correct |
1 ms |
1004 KB |
Output is correct |
25 |
Correct |
1 ms |
1132 KB |
Output is correct |
26 |
Correct |
1 ms |
1132 KB |
Output is correct |
27 |
Correct |
1 ms |
620 KB |
Output is correct |
28 |
Correct |
1 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
1260 KB |
Output is correct |
30 |
Correct |
1 ms |
1260 KB |
Output is correct |
31 |
Correct |
1 ms |
1132 KB |
Output is correct |
32 |
Correct |
1 ms |
1004 KB |
Output is correct |
33 |
Correct |
1 ms |
1260 KB |
Output is correct |
34 |
Correct |
1 ms |
1260 KB |
Output is correct |
35 |
Correct |
1 ms |
1260 KB |
Output is correct |
36 |
Correct |
141 ms |
107500 KB |
Output is correct |
37 |
Correct |
84 ms |
65260 KB |
Output is correct |
38 |
Correct |
34 ms |
34796 KB |
Output is correct |
39 |
Correct |
70 ms |
61696 KB |
Output is correct |
40 |
Correct |
97 ms |
79980 KB |
Output is correct |
41 |
Correct |
29 ms |
29676 KB |
Output is correct |
42 |
Correct |
22 ms |
23276 KB |
Output is correct |
43 |
Correct |
28 ms |
29036 KB |
Output is correct |
44 |
Correct |
10 ms |
11116 KB |
Output is correct |
45 |
Correct |
30 ms |
30316 KB |
Output is correct |
46 |
Correct |
20 ms |
21612 KB |
Output is correct |
47 |
Correct |
35 ms |
30956 KB |
Output is correct |
48 |
Correct |
26 ms |
24448 KB |
Output is correct |
49 |
Correct |
28 ms |
29164 KB |
Output is correct |
50 |
Correct |
13 ms |
15212 KB |
Output is correct |
51 |
Correct |
33 ms |
29036 KB |
Output is correct |
52 |
Correct |
8 ms |
10476 KB |
Output is correct |
53 |
Correct |
28 ms |
28396 KB |
Output is correct |
54 |
Correct |
11 ms |
13548 KB |
Output is correct |
55 |
Correct |
30 ms |
30336 KB |
Output is correct |
56 |
Correct |
14 ms |
16620 KB |
Output is correct |
57 |
Correct |
31 ms |
31596 KB |
Output is correct |
58 |
Correct |
16 ms |
18540 KB |
Output is correct |
59 |
Correct |
167 ms |
132644 KB |
Output is correct |
60 |
Correct |
109 ms |
89452 KB |
Output is correct |
61 |
Correct |
184 ms |
132588 KB |
Output is correct |
62 |
Correct |
109 ms |
88300 KB |
Output is correct |
63 |
Correct |
178 ms |
132588 KB |
Output is correct |
64 |
Correct |
110 ms |
89324 KB |
Output is correct |
65 |
Correct |
157 ms |
119788 KB |
Output is correct |
66 |
Correct |
141 ms |
109932 KB |
Output is correct |
67 |
Correct |
133 ms |
105324 KB |
Output is correct |
68 |
Correct |
125 ms |
97132 KB |
Output is correct |
69 |
Correct |
153 ms |
118508 KB |
Output is correct |
70 |
Correct |
144 ms |
113516 KB |
Output is correct |
71 |
Correct |
134 ms |
114796 KB |
Output is correct |
72 |
Correct |
148 ms |
115948 KB |
Output is correct |
73 |
Correct |
138 ms |
107500 KB |
Output is correct |
74 |
Correct |
123 ms |
100716 KB |
Output is correct |
75 |
Correct |
130 ms |
111084 KB |
Output is correct |
76 |
Correct |
175 ms |
127468 KB |
Output is correct |
77 |
Correct |
173 ms |
127340 KB |
Output is correct |
78 |
Correct |
130 ms |
98284 KB |
Output is correct |
79 |
Correct |
127 ms |
101612 KB |
Output is correct |
80 |
Correct |
167 ms |
124908 KB |
Output is correct |
81 |
Correct |
124 ms |
102872 KB |
Output is correct |
82 |
Correct |
129 ms |
108776 KB |
Output is correct |
83 |
Correct |
183 ms |
132716 KB |
Output is correct |
84 |
Correct |
151 ms |
113640 KB |
Output is correct |
85 |
Correct |
164 ms |
123628 KB |
Output is correct |
86 |
Correct |
168 ms |
120940 KB |
Output is correct |
87 |
Correct |
151 ms |
111212 KB |
Output is correct |
88 |
Correct |
180 ms |
134132 KB |
Output is correct |
89 |
Correct |
179 ms |
134124 KB |
Output is correct |
90 |
Correct |
140 ms |
112332 KB |
Output is correct |
91 |
Correct |
188 ms |
133996 KB |
Output is correct |
92 |
Correct |
176 ms |
133996 KB |
Output is correct |
93 |
Correct |
173 ms |
131308 KB |
Output is correct |