#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+2;
const int mod=1e9+7;
using namespace std;
int i,j,k,p,rs,n;
ll t[nmax],r[nmax],a[nmax],b[nmax],f[nmax][nmax][nmax][2],l;
ll d1(int i,int j)
{
return a[j]-a[i];
}
ll d2(int i,int j)
{
return b[j]-b[i];
}
void upd(ll &x,ll y,ll z)
{
if(y>=llinf)return;
x=min(x,y+z);
}
void upd1(ll &x,ll y,ll z,ll p,ll tt)
{
if(y>=llinf)return;
if(y+z<=tt)x=min(x,y+z+p);
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>l;
for(i=1;i<=n;i++)
{
cin>>a[i];
b[n-i+1]=l-a[i];
}
for(i=1;i<=n;i++)
{
cin>>t[i];
r[n-i+1]=t[i];
}
for(i=0;i<=n;i++)for(j=0;j<=n;j++)for(k=0;k<=n;k++)for(p=0;p<2;p++)f[i][j][k][p]=llinf;
f[0][0][0][0]=f[0][0][0][1]=0;
for(i=0;i<=n;i++)
{
for(j=0;j<=n-i;j++)
{
for(k=0;k<=i+j;k++)
{
if(!i && !j)continue;
if(j)upd(f[i][j][k][0],f[i][j-1][k][1],d1(0,i)+d2(j-1,j)+d2(0,j));
if(j)upd(f[i][j][k][0],f[i][j-1][k][0],d1(0,i)+d1(0,i)+d2(0,j)+d2(0,j));
if(i)upd(f[i][j][k][0],f[i-1][j][k][1],d2(0,j)+d1(0,i));
if(i)upd(f[i][j][k][0],f[i-1][j][k][0],d1(i-1,i));
if(j && k)upd1(f[i][j][k][0],f[i][j-1][k-1][1],d2(j-1,j),d1(0,i)+d2(0,j),r[j]);
if(j && k)upd1(f[i][j][k][0],f[i][j-1][k-1][0],d1(0,i)+d2(0,j),d1(0,i)+d2(0,j),r[j]);
if(i && k)upd1(f[i][j][k][0],f[i-1][j][k-1][1],d2(0,j)+d1(0,i),0,t[i]);
if(i && k)upd1(f[i][j][k][0],f[i-1][j][k-1][0],d1(i-1,i),0,t[i]);
if(j)upd(f[i][j][k][1],f[i][j-1][k][1],d2(j-1,j));
if(j)upd(f[i][j][k][1],f[i][j-1][k][0],d1(0,i)+d2(0,j));
if(i)upd(f[i][j][k][1],f[i-1][j][k][1],d2(0,j)+d1(0,i)+d1(0,i)+d2(0,j));
if(i)upd(f[i][j][k][1],f[i-1][j][k][0],d1(i-1,i)+d1(0,i)+d2(0,j));
if(j && k)upd1(f[i][j][k][1],f[i][j-1][k-1][1],d2(j-1,j),0,r[j]);
if(j && k)upd1(f[i][j][k][1],f[i][j-1][k-1][0],d1(0,i)+d2(0,j),0,r[j]);
if(i && k)upd1(f[i][j][k][1],f[i-1][j][k-1][1],d2(0,j)+d1(0,i),d2(0,j)+d1(0,i),t[i]);
if(i && k)upd1(f[i][j][k][1],f[i-1][j][k-1][0],d1(i-1,i),d1(0,i)+d2(0,j),t[i]);
if(f[i][j][k][0]!=llinf || f[i][j][k][1]!=llinf)rs=max(rs,k);
}
}
}
cout<<rs<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
892 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
4 ms |
636 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
892 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
4 ms |
636 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1016 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
1148 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1016 KB |
Output is correct |
26 |
Correct |
5 ms |
1048 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
1148 KB |
Output is correct |
30 |
Correct |
5 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1016 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1144 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
892 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
4 ms |
636 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
105 ms |
103420 KB |
Output is correct |
19 |
Correct |
62 ms |
62840 KB |
Output is correct |
20 |
Correct |
32 ms |
33528 KB |
Output is correct |
21 |
Correct |
58 ms |
59260 KB |
Output is correct |
22 |
Correct |
77 ms |
76920 KB |
Output is correct |
23 |
Correct |
28 ms |
28536 KB |
Output is correct |
24 |
Correct |
19 ms |
22392 KB |
Output is correct |
25 |
Correct |
29 ms |
27896 KB |
Output is correct |
26 |
Correct |
11 ms |
10744 KB |
Output is correct |
27 |
Correct |
28 ms |
29176 KB |
Output is correct |
28 |
Correct |
18 ms |
20728 KB |
Output is correct |
29 |
Correct |
28 ms |
29816 KB |
Output is correct |
30 |
Correct |
20 ms |
23416 KB |
Output is correct |
31 |
Correct |
29 ms |
28024 KB |
Output is correct |
32 |
Correct |
14 ms |
14712 KB |
Output is correct |
33 |
Correct |
27 ms |
27896 KB |
Output is correct |
34 |
Correct |
13 ms |
10104 KB |
Output is correct |
35 |
Correct |
24 ms |
27384 KB |
Output is correct |
36 |
Correct |
13 ms |
13048 KB |
Output is correct |
37 |
Correct |
25 ms |
29176 KB |
Output is correct |
38 |
Correct |
16 ms |
15992 KB |
Output is correct |
39 |
Correct |
26 ms |
30328 KB |
Output is correct |
40 |
Correct |
17 ms |
17784 KB |
Output is correct |
41 |
Correct |
149 ms |
127584 KB |
Output is correct |
42 |
Correct |
68 ms |
86008 KB |
Output is correct |
43 |
Correct |
150 ms |
127608 KB |
Output is correct |
44 |
Correct |
65 ms |
84984 KB |
Output is correct |
45 |
Correct |
151 ms |
127608 KB |
Output is correct |
46 |
Correct |
63 ms |
86008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
892 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
4 ms |
636 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1016 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
1148 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1016 KB |
Output is correct |
26 |
Correct |
5 ms |
1048 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
1148 KB |
Output is correct |
30 |
Correct |
5 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1016 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1144 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
36 |
Correct |
105 ms |
103420 KB |
Output is correct |
37 |
Correct |
62 ms |
62840 KB |
Output is correct |
38 |
Correct |
32 ms |
33528 KB |
Output is correct |
39 |
Correct |
58 ms |
59260 KB |
Output is correct |
40 |
Correct |
77 ms |
76920 KB |
Output is correct |
41 |
Correct |
28 ms |
28536 KB |
Output is correct |
42 |
Correct |
19 ms |
22392 KB |
Output is correct |
43 |
Correct |
29 ms |
27896 KB |
Output is correct |
44 |
Correct |
11 ms |
10744 KB |
Output is correct |
45 |
Correct |
28 ms |
29176 KB |
Output is correct |
46 |
Correct |
18 ms |
20728 KB |
Output is correct |
47 |
Correct |
28 ms |
29816 KB |
Output is correct |
48 |
Correct |
20 ms |
23416 KB |
Output is correct |
49 |
Correct |
29 ms |
28024 KB |
Output is correct |
50 |
Correct |
14 ms |
14712 KB |
Output is correct |
51 |
Correct |
27 ms |
27896 KB |
Output is correct |
52 |
Correct |
13 ms |
10104 KB |
Output is correct |
53 |
Correct |
24 ms |
27384 KB |
Output is correct |
54 |
Correct |
13 ms |
13048 KB |
Output is correct |
55 |
Correct |
25 ms |
29176 KB |
Output is correct |
56 |
Correct |
16 ms |
15992 KB |
Output is correct |
57 |
Correct |
26 ms |
30328 KB |
Output is correct |
58 |
Correct |
17 ms |
17784 KB |
Output is correct |
59 |
Correct |
149 ms |
127584 KB |
Output is correct |
60 |
Correct |
68 ms |
86008 KB |
Output is correct |
61 |
Correct |
150 ms |
127608 KB |
Output is correct |
62 |
Correct |
65 ms |
84984 KB |
Output is correct |
63 |
Correct |
151 ms |
127608 KB |
Output is correct |
64 |
Correct |
63 ms |
86008 KB |
Output is correct |
65 |
Correct |
119 ms |
115192 KB |
Output is correct |
66 |
Correct |
114 ms |
105828 KB |
Output is correct |
67 |
Correct |
114 ms |
101332 KB |
Output is correct |
68 |
Correct |
93 ms |
93432 KB |
Output is correct |
69 |
Correct |
118 ms |
114040 KB |
Output is correct |
70 |
Correct |
135 ms |
109304 KB |
Output is correct |
71 |
Correct |
109 ms |
110584 KB |
Output is correct |
72 |
Correct |
143 ms |
111608 KB |
Output is correct |
73 |
Correct |
95 ms |
103416 KB |
Output is correct |
74 |
Correct |
116 ms |
96760 KB |
Output is correct |
75 |
Correct |
104 ms |
106872 KB |
Output is correct |
76 |
Correct |
161 ms |
122744 KB |
Output is correct |
77 |
Correct |
126 ms |
122616 KB |
Output is correct |
78 |
Correct |
106 ms |
94584 KB |
Output is correct |
79 |
Correct |
100 ms |
97784 KB |
Output is correct |
80 |
Correct |
144 ms |
120156 KB |
Output is correct |
81 |
Correct |
97 ms |
98936 KB |
Output is correct |
82 |
Correct |
104 ms |
104680 KB |
Output is correct |
83 |
Correct |
127 ms |
127608 KB |
Output is correct |
84 |
Correct |
115 ms |
109432 KB |
Output is correct |
85 |
Correct |
112 ms |
118904 KB |
Output is correct |
86 |
Correct |
118 ms |
116472 KB |
Output is correct |
87 |
Correct |
112 ms |
106872 KB |
Output is correct |
88 |
Correct |
158 ms |
128760 KB |
Output is correct |
89 |
Correct |
152 ms |
128888 KB |
Output is correct |
90 |
Correct |
82 ms |
108152 KB |
Output is correct |
91 |
Correct |
156 ms |
128760 KB |
Output is correct |
92 |
Correct |
153 ms |
128764 KB |
Output is correct |
93 |
Correct |
99 ms |
126456 KB |
Output is correct |