#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=207;
int a[N],t[N];
int DP[N][N][N][2];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,x;
cin>>n>>x;
for(int i=1;i<=n;i++) cin>>a[i];
a[n+1]=x;
for(int i=1;i<=n;i++) cin>>t[i];
for(int l=0;l<=n;l++)
{
for(int r=0;r<=n;r++)
{
for(int i=0;i<=n;i++)
{
DP[l][r][i][0]=inf;
DP[l][r][i][1]=inf;
}
}
}
DP[0][0][0][0]=0;
for(int l=0;l<=n;l++)
{
for(int r=0;r<=n;r++)
{
for(int i=0;i<=n;i++)
{
int d=DP[l][r][i][0]+a[l+1]-a[l];
if(d<=t[l+1]) DP[l+1][r][i+1][0]=min(DP[l+1][r][i+1][0],d);
else DP[l+1][r][i][0]=min(DP[l+1][r][i][0],d);
d=DP[l][r][i][0]+a[l]+(x-a[n-r])%x;
if(d<=t[n-r]) DP[l][r+1][i+1][1]=min(DP[l][r+1][i+1][1],d);
else DP[l][r+1][i][1]=min(DP[l][r+1][i][1],d);
d=DP[l][r][i][1]+a[n-r+1]-a[n-r];
if(d<=t[n-r]) DP[l][r+1][i+1][1]=min(DP[l][r+1][i+1][1],d);
else DP[l][r+1][i][1]=min(DP[l][r+1][i][1],d);
d=DP[l][r][i][1]+(x-a[n-r+1])%x+a[l+1];
if(d<=t[l+1]) DP[l+1][r][i+1][0]=min(DP[l+1][r][i+1][0],d);
else DP[l+1][r][i][0]=min(DP[l+1][r][i][0],d);
}
}
}
int ans=0;
for(int l=0;l<=n;l++)
{
for(int r=0;r<=n;r++)
{
if(l+r>n) continue;
for(int i=0;i<=n;i++)
{
if(min(DP[l][r][i][0],DP[l][r][i][1])!=inf) ans=max(ans,i);
}
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
836 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
704 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
844 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
596 KB |
Output is correct |
18 |
Correct |
53 ms |
54084 KB |
Output is correct |
19 |
Correct |
33 ms |
32952 KB |
Output is correct |
20 |
Correct |
15 ms |
17748 KB |
Output is correct |
21 |
Correct |
28 ms |
31188 KB |
Output is correct |
22 |
Correct |
36 ms |
40252 KB |
Output is correct |
23 |
Correct |
15 ms |
15172 KB |
Output is correct |
24 |
Correct |
10 ms |
11988 KB |
Output is correct |
25 |
Correct |
12 ms |
14932 KB |
Output is correct |
26 |
Correct |
4 ms |
5844 KB |
Output is correct |
27 |
Correct |
12 ms |
15492 KB |
Output is correct |
28 |
Correct |
9 ms |
11144 KB |
Output is correct |
29 |
Correct |
15 ms |
15908 KB |
Output is correct |
30 |
Correct |
10 ms |
12500 KB |
Output is correct |
31 |
Correct |
12 ms |
14868 KB |
Output is correct |
32 |
Correct |
5 ms |
8020 KB |
Output is correct |
33 |
Correct |
12 ms |
14892 KB |
Output is correct |
34 |
Correct |
3 ms |
5460 KB |
Output is correct |
35 |
Correct |
12 ms |
14552 KB |
Output is correct |
36 |
Correct |
5 ms |
7144 KB |
Output is correct |
37 |
Correct |
13 ms |
15512 KB |
Output is correct |
38 |
Correct |
6 ms |
8660 KB |
Output is correct |
39 |
Correct |
13 ms |
16216 KB |
Output is correct |
40 |
Correct |
7 ms |
9672 KB |
Output is correct |
41 |
Correct |
67 ms |
66508 KB |
Output is correct |
42 |
Correct |
40 ms |
44996 KB |
Output is correct |
43 |
Correct |
69 ms |
66496 KB |
Output is correct |
44 |
Correct |
40 ms |
44440 KB |
Output is correct |
45 |
Correct |
66 ms |
66508 KB |
Output is correct |
46 |
Correct |
42 ms |
44924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
836 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
704 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
844 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
36 |
Correct |
53 ms |
54084 KB |
Output is correct |
37 |
Correct |
33 ms |
32952 KB |
Output is correct |
38 |
Correct |
15 ms |
17748 KB |
Output is correct |
39 |
Correct |
28 ms |
31188 KB |
Output is correct |
40 |
Correct |
36 ms |
40252 KB |
Output is correct |
41 |
Correct |
15 ms |
15172 KB |
Output is correct |
42 |
Correct |
10 ms |
11988 KB |
Output is correct |
43 |
Correct |
12 ms |
14932 KB |
Output is correct |
44 |
Correct |
4 ms |
5844 KB |
Output is correct |
45 |
Correct |
12 ms |
15492 KB |
Output is correct |
46 |
Correct |
9 ms |
11144 KB |
Output is correct |
47 |
Correct |
15 ms |
15908 KB |
Output is correct |
48 |
Correct |
10 ms |
12500 KB |
Output is correct |
49 |
Correct |
12 ms |
14868 KB |
Output is correct |
50 |
Correct |
5 ms |
8020 KB |
Output is correct |
51 |
Correct |
12 ms |
14892 KB |
Output is correct |
52 |
Correct |
3 ms |
5460 KB |
Output is correct |
53 |
Correct |
12 ms |
14552 KB |
Output is correct |
54 |
Correct |
5 ms |
7144 KB |
Output is correct |
55 |
Correct |
13 ms |
15512 KB |
Output is correct |
56 |
Correct |
6 ms |
8660 KB |
Output is correct |
57 |
Correct |
13 ms |
16216 KB |
Output is correct |
58 |
Correct |
7 ms |
9672 KB |
Output is correct |
59 |
Correct |
67 ms |
66508 KB |
Output is correct |
60 |
Correct |
40 ms |
44996 KB |
Output is correct |
61 |
Correct |
69 ms |
66496 KB |
Output is correct |
62 |
Correct |
40 ms |
44440 KB |
Output is correct |
63 |
Correct |
66 ms |
66508 KB |
Output is correct |
64 |
Correct |
42 ms |
44924 KB |
Output is correct |
65 |
Correct |
59 ms |
60144 KB |
Output is correct |
66 |
Correct |
53 ms |
55188 KB |
Output is correct |
67 |
Correct |
49 ms |
52796 KB |
Output is correct |
68 |
Correct |
46 ms |
48796 KB |
Output is correct |
69 |
Correct |
60 ms |
59472 KB |
Output is correct |
70 |
Correct |
56 ms |
57064 KB |
Output is correct |
71 |
Correct |
56 ms |
57596 KB |
Output is correct |
72 |
Correct |
56 ms |
58276 KB |
Output is correct |
73 |
Correct |
51 ms |
54092 KB |
Output is correct |
74 |
Correct |
47 ms |
50604 KB |
Output is correct |
75 |
Correct |
52 ms |
55756 KB |
Output is correct |
76 |
Correct |
63 ms |
63948 KB |
Output is correct |
77 |
Correct |
63 ms |
63916 KB |
Output is correct |
78 |
Correct |
46 ms |
49352 KB |
Output is correct |
79 |
Correct |
49 ms |
51048 KB |
Output is correct |
80 |
Correct |
65 ms |
62680 KB |
Output is correct |
81 |
Correct |
49 ms |
51684 KB |
Output is correct |
82 |
Correct |
53 ms |
54616 KB |
Output is correct |
83 |
Correct |
65 ms |
66444 KB |
Output is correct |
84 |
Correct |
63 ms |
57024 KB |
Output is correct |
85 |
Correct |
59 ms |
62028 KB |
Output is correct |
86 |
Correct |
60 ms |
60768 KB |
Output is correct |
87 |
Correct |
55 ms |
55876 KB |
Output is correct |
88 |
Correct |
75 ms |
67196 KB |
Output is correct |
89 |
Correct |
67 ms |
67144 KB |
Output is correct |
90 |
Correct |
57 ms |
56364 KB |
Output is correct |
91 |
Correct |
83 ms |
67148 KB |
Output is correct |
92 |
Correct |
67 ms |
67116 KB |
Output is correct |
93 |
Correct |
65 ms |
65892 KB |
Output is correct |