#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
using namespace std;
ll n,m,k,i,j,ans,a[205],t[205],d[205][205][25][205];
ll check(int l, int r, int pos, int cnt){
if(cnt==0)return 1e14;
if(l>r)return -1e14;
if(d[l][r][pos][cnt]!=-1)return d[l][r][pos][cnt];
ll ans=-1e14;
int lc;
if(pos==0) lc=l-1;
else lc=r+1;
ans=max(ans,check(l+1,r,0,cnt)-(min(abs(a[l]-a[lc]),m-abs(a[l]-a[lc]))));
ans=max(ans,check(l,r-1,1,cnt)-(min(abs(a[r]-a[lc]),m-abs(a[r]-a[lc]))));
ans=max(ans,min(t[l],check(l+1,r,0,cnt-1))-(min(abs(a[l]-a[lc]),m-abs(a[l]-a[lc]))));
ans=max(ans,min(t[r],check(l,r-1,1,cnt-1))-(min(abs(a[r]-a[lc]),m-abs(a[r]-a[lc]))));
d[l][r][pos][cnt]=ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(k=0; k<n; k++)cin>>a[k];
for(k=0; k<n; k++)cin>>t[k];
memset(d,-1,sizeof d);
ll fans=0;
for(k=0; k<=n; k++) {
if(check(0,n-1,1,k)>=0)fans=k;}
cout<<fans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
451 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
451 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
451 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
451 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |