This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
int n=0;
int k=0;
int pos[205];
int limit[205];
int memo[205][205][2][205];
int dp(int l, int r, bool flag, int cur){
if(cur>200) return 0;
if(l+1>=r) return 0;
if(memo[l][r][flag][cur]!=-1) return memo[l][r][flag][cur];
int ans=0;
int dist=cur;
if(!flag) dist+=(pos[l+1]-pos[l]);
else dist+=(pos[l+1]+k-pos[r]);
ans=max(ans,dp(l+1,r,0,dist)+(dist<=limit[l+1]));
int dist2=cur;
if(flag) dist2+=(pos[r]-pos[r-1]);
else dist2+=(pos[l]+k-pos[r-1]);
ans=max(ans,dp(l,r-1,1,dist2)+(dist2<=limit[r-1]));
return memo[l][r][flag][cur]=ans;
}
void solve(){
cin >> n >> k;
memset(memo,-1,sizeof(memo));
for(int x=1;x<=n;x++) cin >> pos[x];
for(int x=1;x<=n;x++) cin >> limit[x];
pos[n+1]=k;
cout << dp(0,n+1,0,0);
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |