#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=205;
ll N,L;
ll X[MX], T[MX], dp[MX][MX][MX][2];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
for(int i=0;i<MX;i++)
for(int j=0;j<MX;j++)
for(int x=0;x<MX;x++)
for(int k=0;k<2;k++)
dp[i][j][x][k]=1e18;
cin>>N>>L;
for(int i=1;i<=N;i++) cin>>X[i];
for(int i=1;i<=N;i++) cin>>T[i];
dp[0][N+1][0][0]=0;
dp[0][N+1][0][1]=0;
X[N+1]=L;
for(int l=0;l<=N;l++) {
for(int r=N+1;r>l;r--) {
for(int x=0;x<=N;x++) {
// gerakin kanan
ll nxt=dp[l][r][x][0]+X[l+1]-X[l];
if(nxt<=T[l+1])
dp[l+1][r][x+1][0]=min(dp[l+1][r][x+1][0],nxt);
else
dp[l+1][r][x][0]=min(dp[l+1][r][x][0],nxt);
nxt=dp[l][r][x][1]+L-X[r]+X[l+1];
if(nxt<=T[l+1])
dp[l+1][r][x+1][0]=min(dp[l+1][r][x+1][0],nxt);
else
dp[l+1][r][x][0]=min(dp[l+1][r][x][0],nxt);
// gerakin kiri
nxt=dp[l][r][x][1]+X[r]-X[r-1];
if(nxt<=T[r-1])
dp[l][r-1][x+1][1]=min(dp[l][r-1][x+1][1],nxt);
else
dp[l][r-1][x][1]=min(dp[l][r-1][x][1],nxt);
nxt=dp[l][r][x][0]+X[l]+L-X[r-1];
if(nxt<=T[r-1])
dp[l][r-1][x+1][1]=min(dp[l][r-1][x+1][1],nxt);
else
dp[l][r-1][x][1]=min(dp[l][r-1][x][1],nxt);
}
}
}
int ans=0;
for(int l=0;l<=N;l++) {
for(int r=N+1;r>l;r--) {
for(int x=0;x<=N;x++) {
if(min(dp[l][r][x][0],dp[l][r][x][1])!=1e18)
ans=max(ans,x);
}
}
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
135252 KB |
Output is correct |
2 |
Correct |
25 ms |
135252 KB |
Output is correct |
3 |
Correct |
25 ms |
135256 KB |
Output is correct |
4 |
Correct |
31 ms |
135248 KB |
Output is correct |
5 |
Correct |
24 ms |
135252 KB |
Output is correct |
6 |
Correct |
27 ms |
135296 KB |
Output is correct |
7 |
Correct |
27 ms |
135332 KB |
Output is correct |
8 |
Correct |
24 ms |
135148 KB |
Output is correct |
9 |
Correct |
24 ms |
135332 KB |
Output is correct |
10 |
Correct |
24 ms |
135260 KB |
Output is correct |
11 |
Correct |
26 ms |
135220 KB |
Output is correct |
12 |
Correct |
27 ms |
135200 KB |
Output is correct |
13 |
Correct |
23 ms |
135260 KB |
Output is correct |
14 |
Correct |
24 ms |
135132 KB |
Output is correct |
15 |
Correct |
25 ms |
135252 KB |
Output is correct |
16 |
Correct |
24 ms |
135332 KB |
Output is correct |
17 |
Correct |
26 ms |
135260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
135252 KB |
Output is correct |
2 |
Correct |
25 ms |
135252 KB |
Output is correct |
3 |
Correct |
25 ms |
135256 KB |
Output is correct |
4 |
Correct |
31 ms |
135248 KB |
Output is correct |
5 |
Correct |
24 ms |
135252 KB |
Output is correct |
6 |
Correct |
27 ms |
135296 KB |
Output is correct |
7 |
Correct |
27 ms |
135332 KB |
Output is correct |
8 |
Correct |
24 ms |
135148 KB |
Output is correct |
9 |
Correct |
24 ms |
135332 KB |
Output is correct |
10 |
Correct |
24 ms |
135260 KB |
Output is correct |
11 |
Correct |
26 ms |
135220 KB |
Output is correct |
12 |
Correct |
27 ms |
135200 KB |
Output is correct |
13 |
Correct |
23 ms |
135260 KB |
Output is correct |
14 |
Correct |
24 ms |
135132 KB |
Output is correct |
15 |
Correct |
25 ms |
135252 KB |
Output is correct |
16 |
Correct |
24 ms |
135332 KB |
Output is correct |
17 |
Correct |
26 ms |
135260 KB |
Output is correct |
18 |
Correct |
25 ms |
135180 KB |
Output is correct |
19 |
Correct |
25 ms |
135160 KB |
Output is correct |
20 |
Correct |
30 ms |
135280 KB |
Output is correct |
21 |
Correct |
25 ms |
135248 KB |
Output is correct |
22 |
Correct |
24 ms |
135268 KB |
Output is correct |
23 |
Correct |
27 ms |
135152 KB |
Output is correct |
24 |
Correct |
25 ms |
135256 KB |
Output is correct |
25 |
Correct |
23 ms |
135252 KB |
Output is correct |
26 |
Correct |
24 ms |
135112 KB |
Output is correct |
27 |
Correct |
24 ms |
135332 KB |
Output is correct |
28 |
Correct |
26 ms |
135260 KB |
Output is correct |
29 |
Correct |
26 ms |
135260 KB |
Output is correct |
30 |
Correct |
26 ms |
135260 KB |
Output is correct |
31 |
Correct |
24 ms |
135084 KB |
Output is correct |
32 |
Correct |
25 ms |
135256 KB |
Output is correct |
33 |
Correct |
24 ms |
135148 KB |
Output is correct |
34 |
Correct |
25 ms |
135260 KB |
Output is correct |
35 |
Correct |
24 ms |
135252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
135252 KB |
Output is correct |
2 |
Correct |
25 ms |
135252 KB |
Output is correct |
3 |
Correct |
25 ms |
135256 KB |
Output is correct |
4 |
Correct |
31 ms |
135248 KB |
Output is correct |
5 |
Correct |
24 ms |
135252 KB |
Output is correct |
6 |
Correct |
27 ms |
135296 KB |
Output is correct |
7 |
Correct |
27 ms |
135332 KB |
Output is correct |
8 |
Correct |
24 ms |
135148 KB |
Output is correct |
9 |
Correct |
24 ms |
135332 KB |
Output is correct |
10 |
Correct |
24 ms |
135260 KB |
Output is correct |
11 |
Correct |
26 ms |
135220 KB |
Output is correct |
12 |
Correct |
27 ms |
135200 KB |
Output is correct |
13 |
Correct |
23 ms |
135260 KB |
Output is correct |
14 |
Correct |
24 ms |
135132 KB |
Output is correct |
15 |
Correct |
25 ms |
135252 KB |
Output is correct |
16 |
Correct |
24 ms |
135332 KB |
Output is correct |
17 |
Correct |
26 ms |
135260 KB |
Output is correct |
18 |
Correct |
56 ms |
135316 KB |
Output is correct |
19 |
Correct |
40 ms |
135268 KB |
Output is correct |
20 |
Correct |
30 ms |
135260 KB |
Output is correct |
21 |
Correct |
40 ms |
135320 KB |
Output is correct |
22 |
Correct |
48 ms |
135368 KB |
Output is correct |
23 |
Correct |
28 ms |
135260 KB |
Output is correct |
24 |
Correct |
34 ms |
135252 KB |
Output is correct |
25 |
Correct |
30 ms |
135236 KB |
Output is correct |
26 |
Correct |
28 ms |
135156 KB |
Output is correct |
27 |
Correct |
29 ms |
135100 KB |
Output is correct |
28 |
Correct |
28 ms |
135276 KB |
Output is correct |
29 |
Correct |
30 ms |
135252 KB |
Output is correct |
30 |
Correct |
28 ms |
135264 KB |
Output is correct |
31 |
Correct |
29 ms |
135116 KB |
Output is correct |
32 |
Correct |
27 ms |
135204 KB |
Output is correct |
33 |
Correct |
31 ms |
135260 KB |
Output is correct |
34 |
Correct |
31 ms |
135148 KB |
Output is correct |
35 |
Correct |
28 ms |
135140 KB |
Output is correct |
36 |
Correct |
30 ms |
135260 KB |
Output is correct |
37 |
Correct |
29 ms |
135264 KB |
Output is correct |
38 |
Correct |
32 ms |
135340 KB |
Output is correct |
39 |
Correct |
29 ms |
135268 KB |
Output is correct |
40 |
Correct |
27 ms |
135272 KB |
Output is correct |
41 |
Correct |
58 ms |
135296 KB |
Output is correct |
42 |
Correct |
48 ms |
135260 KB |
Output is correct |
43 |
Correct |
67 ms |
135316 KB |
Output is correct |
44 |
Correct |
43 ms |
135092 KB |
Output is correct |
45 |
Correct |
58 ms |
135264 KB |
Output is correct |
46 |
Correct |
44 ms |
135252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
135252 KB |
Output is correct |
2 |
Correct |
25 ms |
135252 KB |
Output is correct |
3 |
Correct |
25 ms |
135256 KB |
Output is correct |
4 |
Correct |
31 ms |
135248 KB |
Output is correct |
5 |
Correct |
24 ms |
135252 KB |
Output is correct |
6 |
Correct |
27 ms |
135296 KB |
Output is correct |
7 |
Correct |
27 ms |
135332 KB |
Output is correct |
8 |
Correct |
24 ms |
135148 KB |
Output is correct |
9 |
Correct |
24 ms |
135332 KB |
Output is correct |
10 |
Correct |
24 ms |
135260 KB |
Output is correct |
11 |
Correct |
26 ms |
135220 KB |
Output is correct |
12 |
Correct |
27 ms |
135200 KB |
Output is correct |
13 |
Correct |
23 ms |
135260 KB |
Output is correct |
14 |
Correct |
24 ms |
135132 KB |
Output is correct |
15 |
Correct |
25 ms |
135252 KB |
Output is correct |
16 |
Correct |
24 ms |
135332 KB |
Output is correct |
17 |
Correct |
26 ms |
135260 KB |
Output is correct |
18 |
Correct |
25 ms |
135180 KB |
Output is correct |
19 |
Correct |
25 ms |
135160 KB |
Output is correct |
20 |
Correct |
30 ms |
135280 KB |
Output is correct |
21 |
Correct |
25 ms |
135248 KB |
Output is correct |
22 |
Correct |
24 ms |
135268 KB |
Output is correct |
23 |
Correct |
27 ms |
135152 KB |
Output is correct |
24 |
Correct |
25 ms |
135256 KB |
Output is correct |
25 |
Correct |
23 ms |
135252 KB |
Output is correct |
26 |
Correct |
24 ms |
135112 KB |
Output is correct |
27 |
Correct |
24 ms |
135332 KB |
Output is correct |
28 |
Correct |
26 ms |
135260 KB |
Output is correct |
29 |
Correct |
26 ms |
135260 KB |
Output is correct |
30 |
Correct |
26 ms |
135260 KB |
Output is correct |
31 |
Correct |
24 ms |
135084 KB |
Output is correct |
32 |
Correct |
25 ms |
135256 KB |
Output is correct |
33 |
Correct |
24 ms |
135148 KB |
Output is correct |
34 |
Correct |
25 ms |
135260 KB |
Output is correct |
35 |
Correct |
24 ms |
135252 KB |
Output is correct |
36 |
Correct |
56 ms |
135316 KB |
Output is correct |
37 |
Correct |
40 ms |
135268 KB |
Output is correct |
38 |
Correct |
30 ms |
135260 KB |
Output is correct |
39 |
Correct |
40 ms |
135320 KB |
Output is correct |
40 |
Correct |
48 ms |
135368 KB |
Output is correct |
41 |
Correct |
28 ms |
135260 KB |
Output is correct |
42 |
Correct |
34 ms |
135252 KB |
Output is correct |
43 |
Correct |
30 ms |
135236 KB |
Output is correct |
44 |
Correct |
28 ms |
135156 KB |
Output is correct |
45 |
Correct |
29 ms |
135100 KB |
Output is correct |
46 |
Correct |
28 ms |
135276 KB |
Output is correct |
47 |
Correct |
30 ms |
135252 KB |
Output is correct |
48 |
Correct |
28 ms |
135264 KB |
Output is correct |
49 |
Correct |
29 ms |
135116 KB |
Output is correct |
50 |
Correct |
27 ms |
135204 KB |
Output is correct |
51 |
Correct |
31 ms |
135260 KB |
Output is correct |
52 |
Correct |
31 ms |
135148 KB |
Output is correct |
53 |
Correct |
28 ms |
135140 KB |
Output is correct |
54 |
Correct |
30 ms |
135260 KB |
Output is correct |
55 |
Correct |
29 ms |
135264 KB |
Output is correct |
56 |
Correct |
32 ms |
135340 KB |
Output is correct |
57 |
Correct |
29 ms |
135268 KB |
Output is correct |
58 |
Correct |
27 ms |
135272 KB |
Output is correct |
59 |
Correct |
58 ms |
135296 KB |
Output is correct |
60 |
Correct |
48 ms |
135260 KB |
Output is correct |
61 |
Correct |
67 ms |
135316 KB |
Output is correct |
62 |
Correct |
43 ms |
135092 KB |
Output is correct |
63 |
Correct |
58 ms |
135264 KB |
Output is correct |
64 |
Correct |
44 ms |
135252 KB |
Output is correct |
65 |
Correct |
55 ms |
135320 KB |
Output is correct |
66 |
Correct |
54 ms |
135192 KB |
Output is correct |
67 |
Correct |
52 ms |
135160 KB |
Output is correct |
68 |
Correct |
46 ms |
135220 KB |
Output is correct |
69 |
Correct |
61 ms |
135108 KB |
Output is correct |
70 |
Correct |
53 ms |
135332 KB |
Output is correct |
71 |
Correct |
59 ms |
135320 KB |
Output is correct |
72 |
Correct |
56 ms |
135316 KB |
Output is correct |
73 |
Correct |
54 ms |
135144 KB |
Output is correct |
74 |
Correct |
53 ms |
135312 KB |
Output is correct |
75 |
Correct |
58 ms |
135312 KB |
Output is correct |
76 |
Correct |
60 ms |
135316 KB |
Output is correct |
77 |
Correct |
62 ms |
135260 KB |
Output is correct |
78 |
Correct |
50 ms |
135272 KB |
Output is correct |
79 |
Correct |
52 ms |
135336 KB |
Output is correct |
80 |
Correct |
58 ms |
135320 KB |
Output is correct |
81 |
Correct |
51 ms |
135260 KB |
Output is correct |
82 |
Correct |
54 ms |
135216 KB |
Output is correct |
83 |
Correct |
64 ms |
135108 KB |
Output is correct |
84 |
Correct |
52 ms |
135316 KB |
Output is correct |
85 |
Correct |
62 ms |
135312 KB |
Output is correct |
86 |
Correct |
59 ms |
135260 KB |
Output is correct |
87 |
Correct |
59 ms |
135184 KB |
Output is correct |
88 |
Correct |
61 ms |
135256 KB |
Output is correct |
89 |
Correct |
68 ms |
135108 KB |
Output is correct |
90 |
Correct |
58 ms |
135316 KB |
Output is correct |
91 |
Correct |
71 ms |
135248 KB |
Output is correct |
92 |
Correct |
65 ms |
135256 KB |
Output is correct |
93 |
Correct |
63 ms |
135316 KB |
Output is correct |