//challenge: 100
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define v vector
int n,L;
vector<int> x,t;
v<v<v<v<int>>>> dp;
const int INF=1e18;
int dis(int a,int b){
return min(abs(x[a]-x[b]),L-abs(x[a]-x[b]));
}
int f(int l,int r,int cnt,int s){
if(cnt==0){
return INF;
}
if(r-l+1<cnt){
return -INF;
}
if(dp[l][r][cnt][s]!=-INF){
return dp[l][r][cnt][s];
}
int now=0;
if(s==0){
now=l-1;
}
else{
now=r+1;
}
dp[l][r][cnt][s]=max(dp[l][r][cnt][s],f(l+1,r,cnt,0)-dis(now,l));
dp[l][r][cnt][s]=max(dp[l][r][cnt][s],f(l,r-1,cnt,1)-dis(now,r));
dp[l][r][cnt][s]=max(dp[l][r][cnt][s],min(f(l+1,r,cnt-1,0),t[l])-dis(now,l));
dp[l][r][cnt][s]=max(dp[l][r][cnt][s],min(f(l,r-1,cnt-1,1),t[r])-dis(now,r));
return dp[l][r][cnt][s];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>L;
t.resize(n+2);
x.resize(n+2);
for(int i=1;i<=n;i++){
cin>>x[i];
}
for(int i=1;i<=n;i++){
cin>>t[i];
}
dp.resize(n+2,v<v<v<int>>>(n+2,v<v<int>>(n+2,v<int>(2,-INF))));
int ans=0;
for(int i=1;i<=n;i++){
if(f(1,n,i,0)>=0){
ans=i;
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
316 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
316 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
572 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
316 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
469 ms |
328076 KB |
Output is correct |
19 |
Correct |
226 ms |
155600 KB |
Output is correct |
20 |
Correct |
82 ms |
61000 KB |
Output is correct |
21 |
Correct |
194 ms |
142940 KB |
Output is correct |
22 |
Correct |
287 ms |
210624 KB |
Output is correct |
23 |
Correct |
65 ms |
48040 KB |
Output is correct |
24 |
Correct |
43 ms |
33456 KB |
Output is correct |
25 |
Correct |
63 ms |
46600 KB |
Output is correct |
26 |
Correct |
14 ms |
11344 KB |
Output is correct |
27 |
Correct |
64 ms |
49668 KB |
Output is correct |
28 |
Correct |
39 ms |
29940 KB |
Output is correct |
29 |
Correct |
70 ms |
51136 KB |
Output is correct |
30 |
Correct |
48 ms |
35812 KB |
Output is correct |
31 |
Correct |
64 ms |
46648 KB |
Output is correct |
32 |
Correct |
27 ms |
17996 KB |
Output is correct |
33 |
Correct |
60 ms |
46560 KB |
Output is correct |
34 |
Correct |
13 ms |
10196 KB |
Output is correct |
35 |
Correct |
60 ms |
45108 KB |
Output is correct |
36 |
Correct |
20 ms |
15060 KB |
Output is correct |
37 |
Correct |
68 ms |
49564 KB |
Output is correct |
38 |
Correct |
31 ms |
20308 KB |
Output is correct |
39 |
Correct |
80 ms |
52680 KB |
Output is correct |
40 |
Correct |
32 ms |
23892 KB |
Output is correct |
41 |
Correct |
668 ms |
448716 KB |
Output is correct |
42 |
Correct |
371 ms |
248780 KB |
Output is correct |
43 |
Correct |
667 ms |
448788 KB |
Output is correct |
44 |
Correct |
341 ms |
244532 KB |
Output is correct |
45 |
Correct |
685 ms |
448812 KB |
Output is correct |
46 |
Correct |
334 ms |
248780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
316 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
572 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
469 ms |
328076 KB |
Output is correct |
37 |
Correct |
226 ms |
155600 KB |
Output is correct |
38 |
Correct |
82 ms |
61000 KB |
Output is correct |
39 |
Correct |
194 ms |
142940 KB |
Output is correct |
40 |
Correct |
287 ms |
210624 KB |
Output is correct |
41 |
Correct |
65 ms |
48040 KB |
Output is correct |
42 |
Correct |
43 ms |
33456 KB |
Output is correct |
43 |
Correct |
63 ms |
46600 KB |
Output is correct |
44 |
Correct |
14 ms |
11344 KB |
Output is correct |
45 |
Correct |
64 ms |
49668 KB |
Output is correct |
46 |
Correct |
39 ms |
29940 KB |
Output is correct |
47 |
Correct |
70 ms |
51136 KB |
Output is correct |
48 |
Correct |
48 ms |
35812 KB |
Output is correct |
49 |
Correct |
64 ms |
46648 KB |
Output is correct |
50 |
Correct |
27 ms |
17996 KB |
Output is correct |
51 |
Correct |
60 ms |
46560 KB |
Output is correct |
52 |
Correct |
13 ms |
10196 KB |
Output is correct |
53 |
Correct |
60 ms |
45108 KB |
Output is correct |
54 |
Correct |
20 ms |
15060 KB |
Output is correct |
55 |
Correct |
68 ms |
49564 KB |
Output is correct |
56 |
Correct |
31 ms |
20308 KB |
Output is correct |
57 |
Correct |
80 ms |
52680 KB |
Output is correct |
58 |
Correct |
32 ms |
23892 KB |
Output is correct |
59 |
Correct |
668 ms |
448716 KB |
Output is correct |
60 |
Correct |
371 ms |
248780 KB |
Output is correct |
61 |
Correct |
667 ms |
448788 KB |
Output is correct |
62 |
Correct |
341 ms |
244532 KB |
Output is correct |
63 |
Correct |
685 ms |
448812 KB |
Output is correct |
64 |
Correct |
334 ms |
248780 KB |
Output is correct |
65 |
Correct |
617 ms |
385284 KB |
Output is correct |
66 |
Correct |
496 ms |
339160 KB |
Output is correct |
67 |
Correct |
467 ms |
317260 KB |
Output is correct |
68 |
Correct |
406 ms |
281940 KB |
Output is correct |
69 |
Correct |
528 ms |
379572 KB |
Output is correct |
70 |
Correct |
488 ms |
356284 KB |
Output is correct |
71 |
Correct |
525 ms |
361668 KB |
Output is correct |
72 |
Correct |
538 ms |
367684 KB |
Output is correct |
73 |
Correct |
467 ms |
328012 KB |
Output is correct |
74 |
Correct |
427 ms |
296644 KB |
Output is correct |
75 |
Correct |
503 ms |
344936 KB |
Output is correct |
76 |
Correct |
607 ms |
422656 KB |
Output is correct |
77 |
Correct |
588 ms |
422728 KB |
Output is correct |
78 |
Correct |
396 ms |
286528 KB |
Output is correct |
79 |
Correct |
424 ms |
301884 KB |
Output is correct |
80 |
Correct |
615 ms |
409976 KB |
Output is correct |
81 |
Correct |
441 ms |
307020 KB |
Output is correct |
82 |
Correct |
460 ms |
333696 KB |
Output is correct |
83 |
Correct |
687 ms |
448788 KB |
Output is correct |
84 |
Correct |
497 ms |
356232 KB |
Output is correct |
85 |
Correct |
554 ms |
403952 KB |
Output is correct |
86 |
Correct |
609 ms |
391556 KB |
Output is correct |
87 |
Correct |
537 ms |
344860 KB |
Output is correct |
88 |
Correct |
650 ms |
455852 KB |
Output is correct |
89 |
Correct |
665 ms |
455824 KB |
Output is correct |
90 |
Correct |
518 ms |
350248 KB |
Output is correct |
91 |
Correct |
655 ms |
456064 KB |
Output is correct |
92 |
Correct |
651 ms |
455908 KB |
Output is correct |
93 |
Correct |
671 ms |
442460 KB |
Output is correct |