#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
const ll INF=1e18;
ll dp[205][205][205][2];
ll a[205],t[205];
void upd(ll &x,ll &y)
{
if(x>y) x=y;
}
int main()
{
ll n,L,ans=0;
cin>>n>>L;
rep1(i,n) cin>>a[i];
rep1(i,n) cin>>t[i];
rep(i,n+1) rep(j,n+2) rep(k,n+1) rep(l,2) dp[i][j][k][l]=INF+1;
dp[0][n+1][0][0]=0;
rep(i,n+1)
{
for(int j=n+1;j>=i+1;j--)
{
rep(k,i+n+1-j+1)
{
rep(l,2)
{
if(dp[i][j][k][l]>INF) continue;
ll cur=dp[i][j][k][l];
ans=max(ans,k);
if(l==0)
{
if(i<n)
{
ll tmp=cur+a[i+1]-a[i];
upd(dp[i+1][j][k+(tmp<=t[i+1])][0],tmp);
}
if(j>1)
{
ll tmp=cur+a[i]+L-a[j-1];
upd(dp[i][j-1][k+(tmp<=t[j-1])][1],tmp);
}
}
else
{
if(i<n)
{
ll tmp=cur+L-a[j]+a[i+1];
upd(dp[i+1][j][k+(tmp<=t[i+1])][0],tmp);
}
if(j>1)
{
ll tmp=cur+a[j]-a[j-1];
upd(dp[i][j-1][k+(tmp<=t[j-1])][1],tmp);
}
}
}
}
}
}
cout<<ans;
}
# |
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 |
748 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 |
876 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 |
364 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 |
748 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 |
876 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 |
364 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 |
640 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 |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1132 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
748 KB |
Output is correct |
29 |
Correct |
1 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 |
748 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 |
876 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 |
364 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 |
90 ms |
105580 KB |
Output is correct |
19 |
Correct |
52 ms |
64108 KB |
Output is correct |
20 |
Correct |
26 ms |
34304 KB |
Output is correct |
21 |
Correct |
48 ms |
60632 KB |
Output is correct |
22 |
Correct |
66 ms |
78444 KB |
Output is correct |
23 |
Correct |
23 ms |
29292 KB |
Output is correct |
24 |
Correct |
15 ms |
22892 KB |
Output is correct |
25 |
Correct |
22 ms |
28652 KB |
Output is correct |
26 |
Correct |
7 ms |
11116 KB |
Output is correct |
27 |
Correct |
24 ms |
29932 KB |
Output is correct |
28 |
Correct |
14 ms |
21376 KB |
Output is correct |
29 |
Correct |
23 ms |
30444 KB |
Output is correct |
30 |
Correct |
16 ms |
24044 KB |
Output is correct |
31 |
Correct |
21 ms |
28652 KB |
Output is correct |
32 |
Correct |
10 ms |
15084 KB |
Output is correct |
33 |
Correct |
21 ms |
28672 KB |
Output is correct |
34 |
Correct |
7 ms |
10348 KB |
Output is correct |
35 |
Correct |
19 ms |
28012 KB |
Output is correct |
36 |
Correct |
9 ms |
13420 KB |
Output is correct |
37 |
Correct |
20 ms |
29952 KB |
Output is correct |
38 |
Correct |
11 ms |
16492 KB |
Output is correct |
39 |
Correct |
24 ms |
31084 KB |
Output is correct |
40 |
Correct |
12 ms |
18284 KB |
Output is correct |
41 |
Correct |
121 ms |
130156 KB |
Output is correct |
42 |
Correct |
59 ms |
87788 KB |
Output is correct |
43 |
Correct |
123 ms |
130156 KB |
Output is correct |
44 |
Correct |
57 ms |
86764 KB |
Output is correct |
45 |
Correct |
122 ms |
130156 KB |
Output is correct |
46 |
Correct |
57 ms |
87788 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 |
748 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 |
876 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 |
364 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 |
640 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 |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1132 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
748 KB |
Output is correct |
29 |
Correct |
1 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 |
90 ms |
105580 KB |
Output is correct |
37 |
Correct |
52 ms |
64108 KB |
Output is correct |
38 |
Correct |
26 ms |
34304 KB |
Output is correct |
39 |
Correct |
48 ms |
60632 KB |
Output is correct |
40 |
Correct |
66 ms |
78444 KB |
Output is correct |
41 |
Correct |
23 ms |
29292 KB |
Output is correct |
42 |
Correct |
15 ms |
22892 KB |
Output is correct |
43 |
Correct |
22 ms |
28652 KB |
Output is correct |
44 |
Correct |
7 ms |
11116 KB |
Output is correct |
45 |
Correct |
24 ms |
29932 KB |
Output is correct |
46 |
Correct |
14 ms |
21376 KB |
Output is correct |
47 |
Correct |
23 ms |
30444 KB |
Output is correct |
48 |
Correct |
16 ms |
24044 KB |
Output is correct |
49 |
Correct |
21 ms |
28652 KB |
Output is correct |
50 |
Correct |
10 ms |
15084 KB |
Output is correct |
51 |
Correct |
21 ms |
28672 KB |
Output is correct |
52 |
Correct |
7 ms |
10348 KB |
Output is correct |
53 |
Correct |
19 ms |
28012 KB |
Output is correct |
54 |
Correct |
9 ms |
13420 KB |
Output is correct |
55 |
Correct |
20 ms |
29952 KB |
Output is correct |
56 |
Correct |
11 ms |
16492 KB |
Output is correct |
57 |
Correct |
24 ms |
31084 KB |
Output is correct |
58 |
Correct |
12 ms |
18284 KB |
Output is correct |
59 |
Correct |
121 ms |
130156 KB |
Output is correct |
60 |
Correct |
59 ms |
87788 KB |
Output is correct |
61 |
Correct |
123 ms |
130156 KB |
Output is correct |
62 |
Correct |
57 ms |
86764 KB |
Output is correct |
63 |
Correct |
122 ms |
130156 KB |
Output is correct |
64 |
Correct |
57 ms |
87788 KB |
Output is correct |
65 |
Correct |
107 ms |
117484 KB |
Output is correct |
66 |
Correct |
97 ms |
107884 KB |
Output is correct |
67 |
Correct |
90 ms |
103276 KB |
Output is correct |
68 |
Correct |
81 ms |
95340 KB |
Output is correct |
69 |
Correct |
109 ms |
116332 KB |
Output is correct |
70 |
Correct |
106 ms |
111468 KB |
Output is correct |
71 |
Correct |
98 ms |
112620 KB |
Output is correct |
72 |
Correct |
111 ms |
113900 KB |
Output is correct |
73 |
Correct |
85 ms |
105580 KB |
Output is correct |
74 |
Correct |
105 ms |
98668 KB |
Output is correct |
75 |
Correct |
93 ms |
109096 KB |
Output is correct |
76 |
Correct |
118 ms |
125036 KB |
Output is correct |
77 |
Correct |
111 ms |
125036 KB |
Output is correct |
78 |
Correct |
87 ms |
96492 KB |
Output is correct |
79 |
Correct |
88 ms |
99820 KB |
Output is correct |
80 |
Correct |
116 ms |
122476 KB |
Output is correct |
81 |
Correct |
90 ms |
100972 KB |
Output is correct |
82 |
Correct |
87 ms |
106732 KB |
Output is correct |
83 |
Correct |
115 ms |
130156 KB |
Output is correct |
84 |
Correct |
90 ms |
111468 KB |
Output is correct |
85 |
Correct |
98 ms |
121324 KB |
Output is correct |
86 |
Correct |
98 ms |
118892 KB |
Output is correct |
87 |
Correct |
97 ms |
109036 KB |
Output is correct |
88 |
Correct |
132 ms |
131436 KB |
Output is correct |
89 |
Correct |
128 ms |
131436 KB |
Output is correct |
90 |
Correct |
73 ms |
110316 KB |
Output is correct |
91 |
Correct |
134 ms |
131436 KB |
Output is correct |
92 |
Correct |
122 ms |
131436 KB |
Output is correct |
93 |
Correct |
85 ms |
128876 KB |
Output is correct |