//#include<i_am_noob_orz>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcountll((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define jimmy_is_kind false
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
//#define LOCAL
#ifdef LOCAL
#define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif
int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);}
int sub(int a,int b){return(a<b?a+mod-b:a-b);}
int po(int a,int b){
if(b==0)return 1;
if(b==1)return(a%mod);
int tem=po(a,b/2);
if(b&1)return(((tem*tem)%mod)*a)%mod;
else return(tem*tem)%mod;
}
int GCD(int a,int b){
int x=0;
int ra,rb;
while(a&&b){
if(((a&1)==0)&&((b&1)==0)){
a>>=1,b>>=1,x++;
}
else if((a^b)&1){
if(a&1)b>>=1;
else a>>=1;
}
else{
ra=abs(a-b),rb=min(a,b);
a=ra,b=rb;
}
}
return max(a,b)<<x;
}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int n,l,a[205],b[205],dp[205][205][205][2];
signed main(){
IOS();
cin>>n>>l;
F(n)cin>>a[i+1];
F(n)cin>>b[i+1];
int ans=0;
F(n+1)Fi(j,n+1)Fi(l,n+1)dp[i][j][l][0]=dp[i][j][l][1]=1e15;
dp[0][0][0][0]=dp[0][0][0][1]=0;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
for(int k=0;k<=i;k++){
if(i==j){
dp[n][j][k][0]=min(dp[n][j][k][0],dp[0][j][k][0]+l-a[n]);
if(dp[0][j][k][0]+l-a[n]<=b[n])dp[n][j][k+1][0]=min(dp[n][j][k+1][0],dp[0][j][k][0]+l-a[n]);
dp[n][j][k][0]=min(dp[n][j][k][0],dp[0][j][k][1]+a[j]+l-a[n]);
if(dp[0][j][k][1]+a[j]+l-a[n]<=b[n])dp[n][j][k+1][0]=min(dp[n][j][k+1][0],dp[0][j][k][1]+a[j]+l-a[n]);
dp[0][j+1][k][1]=min(dp[0][j+1][k][1],dp[0][j][k][0]+a[j+1]);
if(dp[0][j][k][0]+a[j+1]<=b[j+1])dp[0][j+1][k+1][1]=min(dp[0][j+1][k+1][1],dp[0][j][k][0]+a[j+1]);
dp[0][j+1][k][1]=min(dp[0][j+1][k][1],dp[0][j][k][1]+a[j+1]-a[j]);
if(dp[0][j][k][1]+a[j+1]-a[j]<=b[j+1])dp[0][j+1][k+1][1]=min(dp[0][j+1][k+1][1],dp[0][j][k][1]+a[j+1]-a[j]);
continue;
}
dp[n-i+j][j][k][0]=min(dp[n-i+j][j][k][0],dp[n-i+j+1][j][k][0]+a[n-i+j+1]-a[n-i+j]);
if(dp[n-i+j+1][j][k][0]+a[n-i+j+1]-a[n-i+j]<=b[n-i+j])dp[n-i+j][j][k+1][0]=min(dp[n-i+j][j][k+1][0],dp[n-i+j+1][j][k][0]+a[n-i+j+1]-a[n-i+j]);
dp[n-i+j][j][k][0]=min(dp[n-i+j][j][k][0],dp[n-i+j+1][j][k][1]+a[j]+l-a[n-i+j]);
if(dp[n-i+j+1][j][k][1]+a[j]+l-a[n-i+j]<=b[n-i+j])dp[n-i+j][j][k+1][0]=min(dp[n-i+j][j][k+1][0],dp[n-i+j+1][j][k][1]+a[j]+l-a[n-i+j]);
dp[n-i+j+1][j+1][k][1]=min(dp[n-i+j+1][j+1][k][1],dp[n-i+j+1][j][k][0]+l-a[n-i+j+1]+a[j+1]);
if(dp[n-i+j+1][j][k][0]+l-a[n-i+j+1]+a[j+1]<=b[j+1])dp[n-i+j+1][j+1][k+1][1]=min(dp[n-i+j+1][j+1][k+1][1],dp[n-i+j+1][j][k][0]+l-a[n-i+j+1]+a[j+1]);
dp[n-i+j+1][j+1][k][1]=min(dp[n-i+j+1][j+1][k][1],dp[n-i+j+1][j][k][1]+a[j+1]-a[j]);
if(dp[n-i+j+1][j][k][1]+a[j+1]-a[j]<=b[j+1])dp[n-i+j+1][j+1][k+1][1]=min(dp[n-i+j+1][j+1][k+1][1],dp[n-i+j+1][j][k][1]+a[j+1]-a[j]);
}
}
}
F(n+1)Fi(j,n+1)Fi(k,n+1){
if(dp[i][j][k][0]<1e14)ans=max(ans,k);
if(dp[i][j][k][1]<1e14)ans=max(ans,k);
}
cout<<ans<<endl;
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 |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
584 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 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 |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
584 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
836 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 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 |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
584 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
63 ms |
104908 KB |
Output is correct |
19 |
Correct |
39 ms |
63560 KB |
Output is correct |
20 |
Correct |
22 ms |
34012 KB |
Output is correct |
21 |
Correct |
37 ms |
60124 KB |
Output is correct |
22 |
Correct |
47 ms |
77952 KB |
Output is correct |
23 |
Correct |
20 ms |
28884 KB |
Output is correct |
24 |
Correct |
14 ms |
22600 KB |
Output is correct |
25 |
Correct |
17 ms |
28232 KB |
Output is correct |
26 |
Correct |
6 ms |
10820 KB |
Output is correct |
27 |
Correct |
18 ms |
29508 KB |
Output is correct |
28 |
Correct |
12 ms |
21092 KB |
Output is correct |
29 |
Correct |
23 ms |
30188 KB |
Output is correct |
30 |
Correct |
14 ms |
23756 KB |
Output is correct |
31 |
Correct |
18 ms |
28352 KB |
Output is correct |
32 |
Correct |
9 ms |
14904 KB |
Output is correct |
33 |
Correct |
22 ms |
28280 KB |
Output is correct |
34 |
Correct |
6 ms |
10068 KB |
Output is correct |
35 |
Correct |
18 ms |
27732 KB |
Output is correct |
36 |
Correct |
8 ms |
13140 KB |
Output is correct |
37 |
Correct |
20 ms |
29524 KB |
Output is correct |
38 |
Correct |
10 ms |
16196 KB |
Output is correct |
39 |
Correct |
20 ms |
30808 KB |
Output is correct |
40 |
Correct |
11 ms |
18056 KB |
Output is correct |
41 |
Correct |
86 ms |
129400 KB |
Output is correct |
42 |
Correct |
56 ms |
87116 KB |
Output is correct |
43 |
Correct |
82 ms |
129356 KB |
Output is correct |
44 |
Correct |
53 ms |
86168 KB |
Output is correct |
45 |
Correct |
91 ms |
129464 KB |
Output is correct |
46 |
Correct |
53 ms |
87124 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 |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
584 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
836 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
36 |
Correct |
63 ms |
104908 KB |
Output is correct |
37 |
Correct |
39 ms |
63560 KB |
Output is correct |
38 |
Correct |
22 ms |
34012 KB |
Output is correct |
39 |
Correct |
37 ms |
60124 KB |
Output is correct |
40 |
Correct |
47 ms |
77952 KB |
Output is correct |
41 |
Correct |
20 ms |
28884 KB |
Output is correct |
42 |
Correct |
14 ms |
22600 KB |
Output is correct |
43 |
Correct |
17 ms |
28232 KB |
Output is correct |
44 |
Correct |
6 ms |
10820 KB |
Output is correct |
45 |
Correct |
18 ms |
29508 KB |
Output is correct |
46 |
Correct |
12 ms |
21092 KB |
Output is correct |
47 |
Correct |
23 ms |
30188 KB |
Output is correct |
48 |
Correct |
14 ms |
23756 KB |
Output is correct |
49 |
Correct |
18 ms |
28352 KB |
Output is correct |
50 |
Correct |
9 ms |
14904 KB |
Output is correct |
51 |
Correct |
22 ms |
28280 KB |
Output is correct |
52 |
Correct |
6 ms |
10068 KB |
Output is correct |
53 |
Correct |
18 ms |
27732 KB |
Output is correct |
54 |
Correct |
8 ms |
13140 KB |
Output is correct |
55 |
Correct |
20 ms |
29524 KB |
Output is correct |
56 |
Correct |
10 ms |
16196 KB |
Output is correct |
57 |
Correct |
20 ms |
30808 KB |
Output is correct |
58 |
Correct |
11 ms |
18056 KB |
Output is correct |
59 |
Correct |
86 ms |
129400 KB |
Output is correct |
60 |
Correct |
56 ms |
87116 KB |
Output is correct |
61 |
Correct |
82 ms |
129356 KB |
Output is correct |
62 |
Correct |
53 ms |
86168 KB |
Output is correct |
63 |
Correct |
91 ms |
129464 KB |
Output is correct |
64 |
Correct |
53 ms |
87124 KB |
Output is correct |
65 |
Correct |
72 ms |
116796 KB |
Output is correct |
66 |
Correct |
68 ms |
107308 KB |
Output is correct |
67 |
Correct |
65 ms |
102632 KB |
Output is correct |
68 |
Correct |
72 ms |
94748 KB |
Output is correct |
69 |
Correct |
73 ms |
115652 KB |
Output is correct |
70 |
Correct |
71 ms |
110852 KB |
Output is correct |
71 |
Correct |
68 ms |
112044 KB |
Output is correct |
72 |
Correct |
73 ms |
113228 KB |
Output is correct |
73 |
Correct |
71 ms |
104980 KB |
Output is correct |
74 |
Correct |
66 ms |
98116 KB |
Output is correct |
75 |
Correct |
76 ms |
108472 KB |
Output is correct |
76 |
Correct |
84 ms |
124376 KB |
Output is correct |
77 |
Correct |
83 ms |
124368 KB |
Output is correct |
78 |
Correct |
62 ms |
95892 KB |
Output is correct |
79 |
Correct |
63 ms |
99208 KB |
Output is correct |
80 |
Correct |
79 ms |
121748 KB |
Output is correct |
81 |
Correct |
69 ms |
100376 KB |
Output is correct |
82 |
Correct |
67 ms |
106080 KB |
Output is correct |
83 |
Correct |
83 ms |
129468 KB |
Output is correct |
84 |
Correct |
72 ms |
110840 KB |
Output is correct |
85 |
Correct |
80 ms |
120544 KB |
Output is correct |
86 |
Correct |
90 ms |
118060 KB |
Output is correct |
87 |
Correct |
71 ms |
108468 KB |
Output is correct |
88 |
Correct |
85 ms |
130720 KB |
Output is correct |
89 |
Correct |
82 ms |
130736 KB |
Output is correct |
90 |
Correct |
70 ms |
109644 KB |
Output is correct |
91 |
Correct |
85 ms |
130668 KB |
Output is correct |
92 |
Correct |
87 ms |
130688 KB |
Output is correct |
93 |
Correct |
83 ms |
128112 KB |
Output is correct |