#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 12, inf = 1e9 + 12;
int n, L, dist[maxn], t[maxn], dp[maxn][maxn][maxn];
int find_ans(int a, int b, int c){
if(c < 0)
return inf;
if(dp[a][b][c] != -1)
return dp[a][b][c];
// cout << a << ' ' << b << ' ' << c << endl;
dp[a][b][c] = inf;
if(a < b){
if(a != 0){
dp[a][b][c] = min(dp[a][b][c], find_ans(a - 1, b, c) + abs(dist[a] - dist[a - 1]));
int x = find_ans(a - 1, b, c - 1) + abs(dist[a] - dist[a - 1]);
if(x <= t[a])
dp[a][b][c] = min(dp[a][b][c], x);
}
if(a != 0){
dp[a][b][c] = min(dp[a][b][c], find_ans(b, a - 1, c) + abs(L - dist[b]) + dist[a]);
int x = find_ans(b, a - 1, c - 1) + abs(L - dist[b]) + dist[a];
if(x <= t[a])
dp[a][b][c] = min(dp[a][b][c], x);
}
}
else if(a > b){
if(a != n){
dp[a][b][c] = min(dp[a][b][c], find_ans((a + 1) % n, b, c) + abs(dist[(a + 1) % n] - dist[a]));
int x = find_ans((a + 1) % n, b, c - 1) + abs(dist[(a + 1) % n] - dist[a]);
if(x <= t[a])
dp[a][b][c] = min(dp[a][b][c], x);
}
if(a != n){
dp[a][b][c] = min(dp[a][b][c], find_ans(b, (a + 1) % n, c) + dist[b] + abs(L - dist[a]));
int x = find_ans(b, (a + 1) % n, c - 1) + dist[b] + abs(L - dist[a]);
if(x <= t[a])
dp[a][b][c] = min(dp[a][b][c], x);
}
}
// if(dp[a][b][c] != inf && c == 5)
// cout << a << ' ' << b << ' ' << c << ' ' << dp[a][b][c] << endl;
return dp[a][b][c];
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
memset(dp, -1, sizeof dp);
cin >> n >> L;
for(int i = 1; i <= n; i++)
cin >> dist[i];
for(int i = 1; i <= n; i++)
cin >> t[i];
dist[0] = 0;
t[0] = 0;
n += 1;
dp[0][0][1] = 0;
dp[0][0][0] = 0;
int ans = 0;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
for(int c = 0; c <= n; c++){
dp[i][j][c] = find_ans(i, j, c);
if(dp[i][j][c] < inf)
ans = max(ans, c);
}
cout << ans - 1 << endl;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:67:27: warning: array subscript -1 is below array bounds of 'int [212]' [-Warray-bounds]
67 | dp[i][j][c] = find_ans(i, j, c);
| ~~~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
37556 KB |
Output is correct |
2 |
Incorrect |
17 ms |
37588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
37556 KB |
Output is correct |
2 |
Incorrect |
17 ms |
37588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
37556 KB |
Output is correct |
2 |
Incorrect |
17 ms |
37588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
37556 KB |
Output is correct |
2 |
Incorrect |
17 ms |
37588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |