#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 202;
const int INF = 0x3f3f3f3f;
int a[N], t[N];
int dp[N][N][N][2];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, p;
cin >> n >> p;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
cin >> t[i];
}
t[0] = -1;
memset(dp, INF, sizeof dp);
int ans = 0;
dp[0][0][0][0] = 0;
for (int c = 0; c < N; ++c) {
for (int l = 0; l <= n; ++l) {
for (int r = 0; r <= n; ++r) {
for (int il = 0; il < 2; ++il) {
if (dp[c][l][r][il] == INF) {
continue;
}
ans = max(ans, c);
int cur = il ? l : r;
int ct = dp[c][l][r][il];
int nl = (l == 0 ? n : l - 1);
int nr = r + 1; //can't cycle ?
int ndl = (l == 0 ? a[cur] + p - a[n] : il ? a[cur] - a[l - 1] : a[cur] + p - a[l - 1]);
int ndr = (l > r && il ? p - a[cur] + a[r + 1] : a[r + 1] - a[cur]);
//deb(c) deb(l) deb(r) deb(ndl) deb(ndr) cout << '\n';
if (nl != r) {
if (ndl + ct <= t[nl]) {
dp[c + 1][nl][r][1] = min(dp[c + 1][nl][r][1], ct + ndl);
}
dp[c][nl][nr][1] = min(dp[c][nl][nr][1], ct + ndl);
}
if (nr != l) {
if (ndr + ct <= t[nr]) {
dp[c + 1][l][nr][0] = min(dp[c + 1][l][nr][0], ct + ndr);
}
dp[c][l][nr][0] = min(dp[c][l][nr][0], ct + ndr);
}
}
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
65012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
65012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
65012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
65012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |