#include<bits/stdc++.h>
using namespace std;
const int N=210;
int dp[N][N][N][2];
const int INF=1e15;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, tot;
cin >> n >> tot;
vector<int> x(n+2);
x[0]=0; x[n+1]=tot;
for(int i=1; i<=n; i++){
cin >> x[i];
}
vector<int> t(n+2);
t[0]=-1; t[n+1]=-1;
for(int i=1; i<=n; i++){
cin >> t[i];
}
//initialize
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
for(int k=0; k<N; k++){
for(int x=0; x<2; x++){
dp[i][j][k][x]=INF;
}
}
}
}
dp[0][0][0][0]=0;
dp[0][0][0][1]=0;
for(int l=0; l<=n; l++){
for(int r=0; r<=n; r++){
//if(l+r>n) continue;
for(int c=0; c<=n; c++){
for(int loc=0; loc<2; loc++){
int cor;
if(loc==0){
cor = x[n+1-l];
}
else{
cor = x[r];
}
//walk right
int distright = 0;
if(loc==0){
distright = (tot-cor) + x[r+1];
}
else{
distright = x[r+1] - cor;
}
dp[l][r+1][c][1] = min(dp[l][r+1][c][1], dp[l][r][c][loc] + distright);
dp[l][r+1][c][0] = min(dp[l][r+1][c][0], dp[l][r][c][loc] + 2*distright);
if( dp[l][r][c][loc] + distright <= t[r+1] ){
dp[l][r+1][c+1][1] = min( dp[l][r+1][c+1][1], dp[l][r][c][loc] + distright );
dp[l][r+1][c+1][0] = min( dp[l][r+1][c+1][0], dp[l][r][c][loc] + 2*distright);
}
//walk left
int distleft=0;
if(loc==0){
distleft = cor - x[n+1 - (l+1)];
}
else{
distleft = tot - x[n+1 - (l+1)] + cor;
}
dp[l+1][r][c][0] = min(dp[l+1][r][c][0], dp[l][r][c][loc] + distleft);
dp[l+1][r][c][1] = min(dp[l+1][r][c][1], dp[l][r][c][loc] + 2*distleft);
if( dp[l][r][c][loc] + distleft <= t[n+1-(l+1)]){
dp[l+1][r][c+1][0] = min(dp[l+1][r][c+1][0], dp[l][r][c][loc] + distleft);
dp[l+1][r][c+1][1] = min(dp[l+1][r][c+1][1], dp[l][r][c][loc] + 2*distleft);
}
}
}
}
}
//finding the largest one
int ans=0;
for(int i=0; i<=n; i++){
for(int j=0; j<=n; j++){
for(int k=0; k<=n; k++){
//cout << i << " " << j << " " << k << ": " << dp[i][j][k][0] << ", " << dp[i][j][k][1] << "\n";
for(int x=0; x<2; x++){
if(dp[i][j][k][x] != INF){
ans = max(ans, k);
}
}
}
}
}
cout << ans << "\n";
}
Compilation message
ho_t3.cpp:7:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
7 | const int INF=1e15;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
72780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
72780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
72780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
72780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |