#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <queue>
#include <cstring>
#include <fstream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define plpll pair<ll, pll>
#define pii pair<int, int>
#define f first
#define s second
#define inf 1000000000000
#define endl '\n'
ll dp[201][201][201][2];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
for(int i=0;i<201;i++) for(int j=0;j<201;j++) for(int k=0;k<201;k++) dp[i][j][k][0]=dp[i][j][k][1]=inf;
ll n, L;
int aans=0;
cin >> n >> L;
ll x[n], t[n];
for(int i=0;i<n;i++) cin >> x[i];
for(int i=0;i<n;i++) cin >> t[i];
dp[0][0][0][0]=dp[0][0][0][1]=0;
dp[0][1][0][1]=x[0];
dp[0][1][0][0]=2*x[0];
if(x[0]<=t[0]){
dp[0][1][1][1]=x[0];
dp[0][1][1][0]=2*x[0];
}
for(int r=2;r<=n;r++){
dp[0][r][0][1]=x[r-1];
dp[0][r][0][0]=2*x[r-1];
for(int ans=1;ans<=r;ans++){
if(dp[0][r-1][ans-1][1]+x[r-1]-x[r-2]<=t[r-1]) dp[0][r][ans][1]=dp[0][r-1][ans-1][1]+x[r-1]-x[r-2];
else dp[0][r][ans][1]=dp[0][r-1][ans][1]+x[r-1]-x[r-2];
dp[0][r][ans][0]=dp[0][r][ans][1]+x[r-1];
}
}
for(int l=1;l<=n;l++){
dp[l][0][0][0]=L-x[n-l];
dp[l][0][0][1]=2*(L-x[n-l]);
for(int ans=1;ans<=l;ans++){
if(l==1){
if(L-x[n-1]<=t[n-1]) dp[1][0][1][0]=L-x[n-1];
}else{
if(dp[l-1][0][ans-1][0]+x[n-l+1]-x[n-l]<=t[n-l]) dp[l][0][ans][0]=dp[l-1][0][ans-1][0]+x[n-l+1]-x[n-l];
else dp[l][0][ans][0]=dp[l-1][0][ans][0]+x[n-l+1]-x[n-l];
}
dp[l][0][ans][1]=dp[l][0][ans][0]+L-x[n-l];
}
for(int r=1;l+r<=n;r++){
for(int ans=1;ans<=l+r;ans++){
if(l==1){
if(dp[l-1][r][ans-1][0]+L-x[n-l]<=t[n-l]) dp[l][r][ans][0]=dp[l-1][r][ans-1][0]+L-x[n-l];
else dp[l][r][ans][0]=dp[l-1][r][ans][0]+L-x[n-l];
}else{
if(dp[l-1][r][ans-1][0]+x[n-l+1]-x[n-l]<=t[n-l]) dp[l][r][ans][0]=dp[l-1][r][ans-1][0]+x[n-l+1]-x[n-l];
else dp[l][r][ans][0]=dp[l-1][r][ans][0]+x[n-l+1]-x[n-l];
}
if(r==1){
if(dp[l][r-1][ans-1][1]+x[r-1]<=t[r-1]) dp[l][r][ans][1]=dp[l][r-1][ans-1][1]+x[r-1];
else dp[l][r][ans][1]=dp[l][r-1][ans][1]+x[r-1];
}else{
if(dp[l][r-1][ans-1][1]+x[r-1]-x[r-2]<=t[r-1]) dp[l][r][ans][1]=dp[l][r-1][ans-1][1]+x[r-1]-x[r-2];
else dp[l][r][ans][1]=dp[l][r-1][ans][1]+x[r-1]-x[r-2];
}
dp[l][r][ans][0]=min(dp[l][r][ans][0], dp[l][r][ans][1]+x[r-1]+L-x[n-l]);
dp[l][r][ans][1]=min(dp[l][r][ans][1], dp[l][r][ans][0]+x[r-1]+L-x[n-l]);
}
}
}
for(int i=0;i<201;i++)
for(int j=0;j<201;j++)
for(int k=0;k<201;k++)
if(dp[i][j][k][0]<inf || dp[i][j][k][1]<inf) aans=max(aans, k);
cout << aans << endl;
/*ll a, b;
while(cin >> a >> b){
for(int i=1;i<=a+b;i++) cout << dp[a][b][i][0] << " ";cout << endl;
for(int i=1;i<=a+b;i++) cout << dp[a][b][i][1] << " ";cout << endl;
}*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
127432 KB |
Output is correct |
2 |
Correct |
59 ms |
127396 KB |
Output is correct |
3 |
Correct |
74 ms |
127408 KB |
Output is correct |
4 |
Correct |
69 ms |
127396 KB |
Output is correct |
5 |
Correct |
61 ms |
127432 KB |
Output is correct |
6 |
Correct |
58 ms |
127420 KB |
Output is correct |
7 |
Correct |
63 ms |
127308 KB |
Output is correct |
8 |
Correct |
63 ms |
127324 KB |
Output is correct |
9 |
Correct |
68 ms |
127424 KB |
Output is correct |
10 |
Correct |
71 ms |
127428 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
62 ms |
127400 KB |
Output is correct |
13 |
Correct |
65 ms |
127404 KB |
Output is correct |
14 |
Correct |
62 ms |
127428 KB |
Output is correct |
15 |
Correct |
61 ms |
127428 KB |
Output is correct |
16 |
Correct |
60 ms |
127428 KB |
Output is correct |
17 |
Correct |
63 ms |
127352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
127432 KB |
Output is correct |
2 |
Correct |
59 ms |
127396 KB |
Output is correct |
3 |
Correct |
74 ms |
127408 KB |
Output is correct |
4 |
Correct |
69 ms |
127396 KB |
Output is correct |
5 |
Correct |
61 ms |
127432 KB |
Output is correct |
6 |
Correct |
58 ms |
127420 KB |
Output is correct |
7 |
Correct |
63 ms |
127308 KB |
Output is correct |
8 |
Correct |
63 ms |
127324 KB |
Output is correct |
9 |
Correct |
68 ms |
127424 KB |
Output is correct |
10 |
Correct |
71 ms |
127428 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
62 ms |
127400 KB |
Output is correct |
13 |
Correct |
65 ms |
127404 KB |
Output is correct |
14 |
Correct |
62 ms |
127428 KB |
Output is correct |
15 |
Correct |
61 ms |
127428 KB |
Output is correct |
16 |
Correct |
60 ms |
127428 KB |
Output is correct |
17 |
Correct |
63 ms |
127352 KB |
Output is correct |
18 |
Correct |
62 ms |
127308 KB |
Output is correct |
19 |
Correct |
74 ms |
127424 KB |
Output is correct |
20 |
Correct |
62 ms |
127328 KB |
Output is correct |
21 |
Correct |
60 ms |
127428 KB |
Output is correct |
22 |
Correct |
64 ms |
127372 KB |
Output is correct |
23 |
Correct |
70 ms |
127308 KB |
Output is correct |
24 |
Correct |
63 ms |
127332 KB |
Output is correct |
25 |
Correct |
62 ms |
127384 KB |
Output is correct |
26 |
Correct |
61 ms |
127392 KB |
Output is correct |
27 |
Correct |
61 ms |
127308 KB |
Output is correct |
28 |
Correct |
63 ms |
127432 KB |
Output is correct |
29 |
Correct |
59 ms |
127364 KB |
Output is correct |
30 |
Correct |
65 ms |
127328 KB |
Output is correct |
31 |
Correct |
67 ms |
127308 KB |
Output is correct |
32 |
Correct |
63 ms |
127432 KB |
Output is correct |
33 |
Correct |
63 ms |
127308 KB |
Output is correct |
34 |
Correct |
61 ms |
127400 KB |
Output is correct |
35 |
Correct |
66 ms |
127424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
127432 KB |
Output is correct |
2 |
Correct |
59 ms |
127396 KB |
Output is correct |
3 |
Correct |
74 ms |
127408 KB |
Output is correct |
4 |
Correct |
69 ms |
127396 KB |
Output is correct |
5 |
Correct |
61 ms |
127432 KB |
Output is correct |
6 |
Correct |
58 ms |
127420 KB |
Output is correct |
7 |
Correct |
63 ms |
127308 KB |
Output is correct |
8 |
Correct |
63 ms |
127324 KB |
Output is correct |
9 |
Correct |
68 ms |
127424 KB |
Output is correct |
10 |
Correct |
71 ms |
127428 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
62 ms |
127400 KB |
Output is correct |
13 |
Correct |
65 ms |
127404 KB |
Output is correct |
14 |
Correct |
62 ms |
127428 KB |
Output is correct |
15 |
Correct |
61 ms |
127428 KB |
Output is correct |
16 |
Correct |
60 ms |
127428 KB |
Output is correct |
17 |
Correct |
63 ms |
127352 KB |
Output is correct |
18 |
Correct |
94 ms |
127424 KB |
Output is correct |
19 |
Correct |
74 ms |
127428 KB |
Output is correct |
20 |
Correct |
72 ms |
127416 KB |
Output is correct |
21 |
Correct |
69 ms |
127380 KB |
Output is correct |
22 |
Correct |
85 ms |
127432 KB |
Output is correct |
23 |
Correct |
65 ms |
127384 KB |
Output is correct |
24 |
Correct |
65 ms |
127320 KB |
Output is correct |
25 |
Correct |
68 ms |
127312 KB |
Output is correct |
26 |
Correct |
60 ms |
127332 KB |
Output is correct |
27 |
Correct |
68 ms |
127384 KB |
Output is correct |
28 |
Correct |
63 ms |
127324 KB |
Output is correct |
29 |
Correct |
64 ms |
127400 KB |
Output is correct |
30 |
Correct |
63 ms |
127340 KB |
Output is correct |
31 |
Correct |
67 ms |
127432 KB |
Output is correct |
32 |
Correct |
61 ms |
127428 KB |
Output is correct |
33 |
Correct |
81 ms |
127312 KB |
Output is correct |
34 |
Correct |
63 ms |
127360 KB |
Output is correct |
35 |
Correct |
62 ms |
127424 KB |
Output is correct |
36 |
Correct |
65 ms |
127348 KB |
Output is correct |
37 |
Correct |
65 ms |
127320 KB |
Output is correct |
38 |
Correct |
67 ms |
127436 KB |
Output is correct |
39 |
Correct |
64 ms |
127428 KB |
Output is correct |
40 |
Correct |
61 ms |
127360 KB |
Output is correct |
41 |
Correct |
77 ms |
127420 KB |
Output is correct |
42 |
Correct |
70 ms |
127428 KB |
Output is correct |
43 |
Correct |
84 ms |
127496 KB |
Output is correct |
44 |
Correct |
73 ms |
127544 KB |
Output is correct |
45 |
Correct |
85 ms |
127356 KB |
Output is correct |
46 |
Correct |
74 ms |
127436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
127432 KB |
Output is correct |
2 |
Correct |
59 ms |
127396 KB |
Output is correct |
3 |
Correct |
74 ms |
127408 KB |
Output is correct |
4 |
Correct |
69 ms |
127396 KB |
Output is correct |
5 |
Correct |
61 ms |
127432 KB |
Output is correct |
6 |
Correct |
58 ms |
127420 KB |
Output is correct |
7 |
Correct |
63 ms |
127308 KB |
Output is correct |
8 |
Correct |
63 ms |
127324 KB |
Output is correct |
9 |
Correct |
68 ms |
127424 KB |
Output is correct |
10 |
Correct |
71 ms |
127428 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
62 ms |
127400 KB |
Output is correct |
13 |
Correct |
65 ms |
127404 KB |
Output is correct |
14 |
Correct |
62 ms |
127428 KB |
Output is correct |
15 |
Correct |
61 ms |
127428 KB |
Output is correct |
16 |
Correct |
60 ms |
127428 KB |
Output is correct |
17 |
Correct |
63 ms |
127352 KB |
Output is correct |
18 |
Correct |
62 ms |
127308 KB |
Output is correct |
19 |
Correct |
74 ms |
127424 KB |
Output is correct |
20 |
Correct |
62 ms |
127328 KB |
Output is correct |
21 |
Correct |
60 ms |
127428 KB |
Output is correct |
22 |
Correct |
64 ms |
127372 KB |
Output is correct |
23 |
Correct |
70 ms |
127308 KB |
Output is correct |
24 |
Correct |
63 ms |
127332 KB |
Output is correct |
25 |
Correct |
62 ms |
127384 KB |
Output is correct |
26 |
Correct |
61 ms |
127392 KB |
Output is correct |
27 |
Correct |
61 ms |
127308 KB |
Output is correct |
28 |
Correct |
63 ms |
127432 KB |
Output is correct |
29 |
Correct |
59 ms |
127364 KB |
Output is correct |
30 |
Correct |
65 ms |
127328 KB |
Output is correct |
31 |
Correct |
67 ms |
127308 KB |
Output is correct |
32 |
Correct |
63 ms |
127432 KB |
Output is correct |
33 |
Correct |
63 ms |
127308 KB |
Output is correct |
34 |
Correct |
61 ms |
127400 KB |
Output is correct |
35 |
Correct |
66 ms |
127424 KB |
Output is correct |
36 |
Correct |
94 ms |
127424 KB |
Output is correct |
37 |
Correct |
74 ms |
127428 KB |
Output is correct |
38 |
Correct |
72 ms |
127416 KB |
Output is correct |
39 |
Correct |
69 ms |
127380 KB |
Output is correct |
40 |
Correct |
85 ms |
127432 KB |
Output is correct |
41 |
Correct |
65 ms |
127384 KB |
Output is correct |
42 |
Correct |
65 ms |
127320 KB |
Output is correct |
43 |
Correct |
68 ms |
127312 KB |
Output is correct |
44 |
Correct |
60 ms |
127332 KB |
Output is correct |
45 |
Correct |
68 ms |
127384 KB |
Output is correct |
46 |
Correct |
63 ms |
127324 KB |
Output is correct |
47 |
Correct |
64 ms |
127400 KB |
Output is correct |
48 |
Correct |
63 ms |
127340 KB |
Output is correct |
49 |
Correct |
67 ms |
127432 KB |
Output is correct |
50 |
Correct |
61 ms |
127428 KB |
Output is correct |
51 |
Correct |
81 ms |
127312 KB |
Output is correct |
52 |
Correct |
63 ms |
127360 KB |
Output is correct |
53 |
Correct |
62 ms |
127424 KB |
Output is correct |
54 |
Correct |
65 ms |
127348 KB |
Output is correct |
55 |
Correct |
65 ms |
127320 KB |
Output is correct |
56 |
Correct |
67 ms |
127436 KB |
Output is correct |
57 |
Correct |
64 ms |
127428 KB |
Output is correct |
58 |
Correct |
61 ms |
127360 KB |
Output is correct |
59 |
Correct |
77 ms |
127420 KB |
Output is correct |
60 |
Correct |
70 ms |
127428 KB |
Output is correct |
61 |
Correct |
84 ms |
127496 KB |
Output is correct |
62 |
Correct |
73 ms |
127544 KB |
Output is correct |
63 |
Correct |
85 ms |
127356 KB |
Output is correct |
64 |
Correct |
74 ms |
127436 KB |
Output is correct |
65 |
Correct |
75 ms |
127328 KB |
Output is correct |
66 |
Correct |
77 ms |
127428 KB |
Output is correct |
67 |
Correct |
72 ms |
127404 KB |
Output is correct |
68 |
Correct |
86 ms |
127336 KB |
Output is correct |
69 |
Correct |
72 ms |
127432 KB |
Output is correct |
70 |
Correct |
80 ms |
127340 KB |
Output is correct |
71 |
Correct |
81 ms |
127308 KB |
Output is correct |
72 |
Correct |
73 ms |
127364 KB |
Output is correct |
73 |
Correct |
86 ms |
127364 KB |
Output is correct |
74 |
Correct |
83 ms |
127432 KB |
Output is correct |
75 |
Correct |
77 ms |
127404 KB |
Output is correct |
76 |
Correct |
87 ms |
127416 KB |
Output is correct |
77 |
Correct |
77 ms |
127368 KB |
Output is correct |
78 |
Correct |
71 ms |
127436 KB |
Output is correct |
79 |
Correct |
94 ms |
127356 KB |
Output is correct |
80 |
Correct |
82 ms |
127360 KB |
Output is correct |
81 |
Correct |
82 ms |
127436 KB |
Output is correct |
82 |
Correct |
79 ms |
127444 KB |
Output is correct |
83 |
Correct |
80 ms |
127480 KB |
Output is correct |
84 |
Correct |
75 ms |
127364 KB |
Output is correct |
85 |
Correct |
78 ms |
127412 KB |
Output is correct |
86 |
Correct |
83 ms |
127344 KB |
Output is correct |
87 |
Correct |
81 ms |
127424 KB |
Output is correct |
88 |
Correct |
76 ms |
127328 KB |
Output is correct |
89 |
Correct |
83 ms |
127416 KB |
Output is correct |
90 |
Correct |
76 ms |
127328 KB |
Output is correct |
91 |
Correct |
90 ms |
127324 KB |
Output is correct |
92 |
Correct |
78 ms |
127388 KB |
Output is correct |
93 |
Correct |
84 ms |
127368 KB |
Output is correct |