#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int INF = 1e18;
const int maxn = 205;
int dp[maxn][maxn][maxn][2] = {0};
int a[maxn] = {0};
int t[maxn] = {0};
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,L;
cin >> n >> L;
for(int j =1;j <= n;++j)
{
cin >> a[j];
}
a[n+1] = L;
for(int j =1;j <= n;++j)
{
cin >> t[j];
}
for(int i = 0;i <= n;++i)
{
for(int j = 0;j <= n;++j)
{
for(int k = 0;k <= n;++k)
{
for(int l = 0;l < 2;++l)
dp[i][j][k][l] = INF;
}
}
}
int ans = 0;
for(int lx = 0;lx <= n;++lx)
{
for(int rx = 0;lx+rx <= n;++rx)
{
for(int k = 0;k <= lx+rx;++k)
{
for(int l = 0;l < 2;++l)
{
if(lx == 0 && rx == 0)
dp[lx][rx][k][l] = 0;
else
{
if(l == 0)
{
if(lx != 0)
{
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx-1][rx][k][0] + a[lx]-a[lx-1]);
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx-1][rx][k][1] + L-a[n-rx+1]+a[lx]);
if(k != 0 && dp[lx-1][rx][k-1][0] + a[lx]-a[lx-1] <= t[lx])
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx-1][rx][k-1][0] + a[lx]-a[lx-1]);
if(k != 0 && dp[lx-1][rx][k-1][1] + L-a[n-rx+1]+a[lx] <= t[lx])
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx-1][rx][k-1][1] + L-a[n-rx+1]+a[lx]);
}
}
else
{
if(rx != 0)
{
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx][rx-1][k][0] + a[lx] + L - a[n-rx+1]);
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx][rx-1][k][1] + a[n-rx+2]-a[n-rx+1]);
if(k != 0 && dp[lx][rx-1][k-1][0] + a[lx] + L - a[n-rx+1] <= t[n-rx+1])
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx][rx-1][k-1][0] + a[lx] + L - a[n-rx+1]);
if(k != 0 && dp[lx][rx-1][k-1][1] + a[n-rx+2]-a[n-rx+1] <= t[n-rx+1])
dp[lx][rx][k][l] = min(dp[lx][rx][k][l],dp[lx][rx-1][k-1][1] + a[n-rx+2]-a[n-rx+1]);
}
}
}
if(dp[lx][rx][k][l] != INF)
{
// cout << lx << ' ' << rx << ' ' << k << ' ' << l << ' ' << dp[lx][rx][k][l] << "\n";
ans = max(ans,k);
}
}
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8536 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
1 ms |
10584 KB |
Output is correct |
25 |
Correct |
1 ms |
10588 KB |
Output is correct |
26 |
Correct |
1 ms |
10588 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
1 ms |
10588 KB |
Output is correct |
31 |
Correct |
1 ms |
10584 KB |
Output is correct |
32 |
Correct |
1 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10584 KB |
Output is correct |
34 |
Correct |
2 ms |
10584 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
39 ms |
119760 KB |
Output is correct |
19 |
Correct |
20 ms |
92816 KB |
Output is correct |
20 |
Correct |
11 ms |
68188 KB |
Output is correct |
21 |
Correct |
20 ms |
90808 KB |
Output is correct |
22 |
Correct |
24 ms |
103004 KB |
Output is correct |
23 |
Correct |
10 ms |
62044 KB |
Output is correct |
24 |
Correct |
8 ms |
55900 KB |
Output is correct |
25 |
Correct |
10 ms |
62044 KB |
Output is correct |
26 |
Correct |
5 ms |
37468 KB |
Output is correct |
27 |
Correct |
11 ms |
64088 KB |
Output is correct |
28 |
Correct |
8 ms |
54108 KB |
Output is correct |
29 |
Correct |
12 ms |
64092 KB |
Output is correct |
30 |
Correct |
8 ms |
55900 KB |
Output is correct |
31 |
Correct |
11 ms |
62044 KB |
Output is correct |
32 |
Correct |
6 ms |
45660 KB |
Output is correct |
33 |
Correct |
10 ms |
62044 KB |
Output is correct |
34 |
Correct |
5 ms |
37468 KB |
Output is correct |
35 |
Correct |
10 ms |
62044 KB |
Output is correct |
36 |
Correct |
5 ms |
41564 KB |
Output is correct |
37 |
Correct |
11 ms |
64092 KB |
Output is correct |
38 |
Correct |
7 ms |
47708 KB |
Output is correct |
39 |
Correct |
11 ms |
64092 KB |
Output is correct |
40 |
Correct |
7 ms |
49756 KB |
Output is correct |
41 |
Correct |
42 ms |
133980 KB |
Output is correct |
42 |
Correct |
27 ms |
109400 KB |
Output is correct |
43 |
Correct |
40 ms |
133980 KB |
Output is correct |
44 |
Correct |
27 ms |
109148 KB |
Output is correct |
45 |
Correct |
40 ms |
133772 KB |
Output is correct |
46 |
Correct |
26 ms |
109144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8536 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
1 ms |
10584 KB |
Output is correct |
25 |
Correct |
1 ms |
10588 KB |
Output is correct |
26 |
Correct |
1 ms |
10588 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
1 ms |
10588 KB |
Output is correct |
31 |
Correct |
1 ms |
10584 KB |
Output is correct |
32 |
Correct |
1 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10584 KB |
Output is correct |
34 |
Correct |
2 ms |
10584 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
39 ms |
119760 KB |
Output is correct |
37 |
Correct |
20 ms |
92816 KB |
Output is correct |
38 |
Correct |
11 ms |
68188 KB |
Output is correct |
39 |
Correct |
20 ms |
90808 KB |
Output is correct |
40 |
Correct |
24 ms |
103004 KB |
Output is correct |
41 |
Correct |
10 ms |
62044 KB |
Output is correct |
42 |
Correct |
8 ms |
55900 KB |
Output is correct |
43 |
Correct |
10 ms |
62044 KB |
Output is correct |
44 |
Correct |
5 ms |
37468 KB |
Output is correct |
45 |
Correct |
11 ms |
64088 KB |
Output is correct |
46 |
Correct |
8 ms |
54108 KB |
Output is correct |
47 |
Correct |
12 ms |
64092 KB |
Output is correct |
48 |
Correct |
8 ms |
55900 KB |
Output is correct |
49 |
Correct |
11 ms |
62044 KB |
Output is correct |
50 |
Correct |
6 ms |
45660 KB |
Output is correct |
51 |
Correct |
10 ms |
62044 KB |
Output is correct |
52 |
Correct |
5 ms |
37468 KB |
Output is correct |
53 |
Correct |
10 ms |
62044 KB |
Output is correct |
54 |
Correct |
5 ms |
41564 KB |
Output is correct |
55 |
Correct |
11 ms |
64092 KB |
Output is correct |
56 |
Correct |
7 ms |
47708 KB |
Output is correct |
57 |
Correct |
11 ms |
64092 KB |
Output is correct |
58 |
Correct |
7 ms |
49756 KB |
Output is correct |
59 |
Correct |
42 ms |
133980 KB |
Output is correct |
60 |
Correct |
27 ms |
109400 KB |
Output is correct |
61 |
Correct |
40 ms |
133980 KB |
Output is correct |
62 |
Correct |
27 ms |
109148 KB |
Output is correct |
63 |
Correct |
40 ms |
133772 KB |
Output is correct |
64 |
Correct |
26 ms |
109144 KB |
Output is correct |
65 |
Correct |
35 ms |
125788 KB |
Output is correct |
66 |
Correct |
34 ms |
121548 KB |
Output is correct |
67 |
Correct |
31 ms |
117596 KB |
Output is correct |
68 |
Correct |
29 ms |
113500 KB |
Output is correct |
69 |
Correct |
37 ms |
125820 KB |
Output is correct |
70 |
Correct |
34 ms |
123736 KB |
Output is correct |
71 |
Correct |
34 ms |
123740 KB |
Output is correct |
72 |
Correct |
37 ms |
123740 KB |
Output is correct |
73 |
Correct |
31 ms |
119644 KB |
Output is correct |
74 |
Correct |
31 ms |
115548 KB |
Output is correct |
75 |
Correct |
33 ms |
121692 KB |
Output is correct |
76 |
Correct |
40 ms |
129788 KB |
Output is correct |
77 |
Correct |
40 ms |
129900 KB |
Output is correct |
78 |
Correct |
31 ms |
115544 KB |
Output is correct |
79 |
Correct |
30 ms |
115548 KB |
Output is correct |
80 |
Correct |
38 ms |
129876 KB |
Output is correct |
81 |
Correct |
30 ms |
117592 KB |
Output is correct |
82 |
Correct |
32 ms |
119644 KB |
Output is correct |
83 |
Correct |
40 ms |
133980 KB |
Output is correct |
84 |
Correct |
33 ms |
123740 KB |
Output is correct |
85 |
Correct |
39 ms |
128080 KB |
Output is correct |
86 |
Correct |
36 ms |
127836 KB |
Output is correct |
87 |
Correct |
33 ms |
121716 KB |
Output is correct |
88 |
Correct |
43 ms |
133832 KB |
Output is correct |
89 |
Correct |
41 ms |
133980 KB |
Output is correct |
90 |
Correct |
32 ms |
121944 KB |
Output is correct |
91 |
Correct |
41 ms |
133972 KB |
Output is correct |
92 |
Correct |
43 ms |
134000 KB |
Output is correct |
93 |
Correct |
39 ms |
131928 KB |
Output is correct |