#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;
dp[0][0][0][1] = 0;
for (int c = 0; c <= n; ++c) {
for (int l = n, tc = 0; tc < 2; l = (l - 1 < 0 ? n : l - 1)) {
tc += l == n;
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;
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]);
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][r][1] = min(dp[c][nl][r][1], ct + ndl);
}
if (nr <= n && 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 |
Correct |
8 ms |
64856 KB |
Output is correct |
2 |
Correct |
8 ms |
64952 KB |
Output is correct |
3 |
Correct |
8 ms |
64860 KB |
Output is correct |
4 |
Correct |
7 ms |
64972 KB |
Output is correct |
5 |
Correct |
7 ms |
64860 KB |
Output is correct |
6 |
Correct |
8 ms |
64860 KB |
Output is correct |
7 |
Correct |
7 ms |
64736 KB |
Output is correct |
8 |
Correct |
8 ms |
64860 KB |
Output is correct |
9 |
Correct |
7 ms |
64860 KB |
Output is correct |
10 |
Correct |
8 ms |
64860 KB |
Output is correct |
11 |
Correct |
8 ms |
64964 KB |
Output is correct |
12 |
Correct |
8 ms |
64920 KB |
Output is correct |
13 |
Correct |
7 ms |
64860 KB |
Output is correct |
14 |
Correct |
8 ms |
64860 KB |
Output is correct |
15 |
Correct |
7 ms |
64860 KB |
Output is correct |
16 |
Correct |
8 ms |
64860 KB |
Output is correct |
17 |
Correct |
8 ms |
64860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
64856 KB |
Output is correct |
2 |
Correct |
8 ms |
64952 KB |
Output is correct |
3 |
Correct |
8 ms |
64860 KB |
Output is correct |
4 |
Correct |
7 ms |
64972 KB |
Output is correct |
5 |
Correct |
7 ms |
64860 KB |
Output is correct |
6 |
Correct |
8 ms |
64860 KB |
Output is correct |
7 |
Correct |
7 ms |
64736 KB |
Output is correct |
8 |
Correct |
8 ms |
64860 KB |
Output is correct |
9 |
Correct |
7 ms |
64860 KB |
Output is correct |
10 |
Correct |
8 ms |
64860 KB |
Output is correct |
11 |
Correct |
8 ms |
64964 KB |
Output is correct |
12 |
Correct |
8 ms |
64920 KB |
Output is correct |
13 |
Correct |
7 ms |
64860 KB |
Output is correct |
14 |
Correct |
8 ms |
64860 KB |
Output is correct |
15 |
Correct |
7 ms |
64860 KB |
Output is correct |
16 |
Correct |
8 ms |
64860 KB |
Output is correct |
17 |
Correct |
8 ms |
64860 KB |
Output is correct |
18 |
Correct |
7 ms |
64860 KB |
Output is correct |
19 |
Correct |
7 ms |
64860 KB |
Output is correct |
20 |
Correct |
7 ms |
64860 KB |
Output is correct |
21 |
Correct |
7 ms |
64976 KB |
Output is correct |
22 |
Correct |
8 ms |
64860 KB |
Output is correct |
23 |
Correct |
7 ms |
64860 KB |
Output is correct |
24 |
Correct |
8 ms |
64976 KB |
Output is correct |
25 |
Correct |
7 ms |
64860 KB |
Output is correct |
26 |
Correct |
7 ms |
64860 KB |
Output is correct |
27 |
Correct |
8 ms |
65112 KB |
Output is correct |
28 |
Correct |
7 ms |
64860 KB |
Output is correct |
29 |
Correct |
8 ms |
64860 KB |
Output is correct |
30 |
Correct |
7 ms |
64964 KB |
Output is correct |
31 |
Correct |
7 ms |
64860 KB |
Output is correct |
32 |
Correct |
7 ms |
64860 KB |
Output is correct |
33 |
Correct |
8 ms |
64860 KB |
Output is correct |
34 |
Correct |
8 ms |
64860 KB |
Output is correct |
35 |
Correct |
7 ms |
64860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
64856 KB |
Output is correct |
2 |
Correct |
8 ms |
64952 KB |
Output is correct |
3 |
Correct |
8 ms |
64860 KB |
Output is correct |
4 |
Correct |
7 ms |
64972 KB |
Output is correct |
5 |
Correct |
7 ms |
64860 KB |
Output is correct |
6 |
Correct |
8 ms |
64860 KB |
Output is correct |
7 |
Correct |
7 ms |
64736 KB |
Output is correct |
8 |
Correct |
8 ms |
64860 KB |
Output is correct |
9 |
Correct |
7 ms |
64860 KB |
Output is correct |
10 |
Correct |
8 ms |
64860 KB |
Output is correct |
11 |
Correct |
8 ms |
64964 KB |
Output is correct |
12 |
Correct |
8 ms |
64920 KB |
Output is correct |
13 |
Correct |
7 ms |
64860 KB |
Output is correct |
14 |
Correct |
8 ms |
64860 KB |
Output is correct |
15 |
Correct |
7 ms |
64860 KB |
Output is correct |
16 |
Correct |
8 ms |
64860 KB |
Output is correct |
17 |
Correct |
8 ms |
64860 KB |
Output is correct |
18 |
Correct |
38 ms |
64952 KB |
Output is correct |
19 |
Correct |
23 ms |
64860 KB |
Output is correct |
20 |
Correct |
14 ms |
64860 KB |
Output is correct |
21 |
Correct |
21 ms |
64860 KB |
Output is correct |
22 |
Correct |
26 ms |
64860 KB |
Output is correct |
23 |
Correct |
15 ms |
64860 KB |
Output is correct |
24 |
Correct |
10 ms |
64912 KB |
Output is correct |
25 |
Correct |
13 ms |
64860 KB |
Output is correct |
26 |
Incorrect |
8 ms |
64860 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
64856 KB |
Output is correct |
2 |
Correct |
8 ms |
64952 KB |
Output is correct |
3 |
Correct |
8 ms |
64860 KB |
Output is correct |
4 |
Correct |
7 ms |
64972 KB |
Output is correct |
5 |
Correct |
7 ms |
64860 KB |
Output is correct |
6 |
Correct |
8 ms |
64860 KB |
Output is correct |
7 |
Correct |
7 ms |
64736 KB |
Output is correct |
8 |
Correct |
8 ms |
64860 KB |
Output is correct |
9 |
Correct |
7 ms |
64860 KB |
Output is correct |
10 |
Correct |
8 ms |
64860 KB |
Output is correct |
11 |
Correct |
8 ms |
64964 KB |
Output is correct |
12 |
Correct |
8 ms |
64920 KB |
Output is correct |
13 |
Correct |
7 ms |
64860 KB |
Output is correct |
14 |
Correct |
8 ms |
64860 KB |
Output is correct |
15 |
Correct |
7 ms |
64860 KB |
Output is correct |
16 |
Correct |
8 ms |
64860 KB |
Output is correct |
17 |
Correct |
8 ms |
64860 KB |
Output is correct |
18 |
Correct |
7 ms |
64860 KB |
Output is correct |
19 |
Correct |
7 ms |
64860 KB |
Output is correct |
20 |
Correct |
7 ms |
64860 KB |
Output is correct |
21 |
Correct |
7 ms |
64976 KB |
Output is correct |
22 |
Correct |
8 ms |
64860 KB |
Output is correct |
23 |
Correct |
7 ms |
64860 KB |
Output is correct |
24 |
Correct |
8 ms |
64976 KB |
Output is correct |
25 |
Correct |
7 ms |
64860 KB |
Output is correct |
26 |
Correct |
7 ms |
64860 KB |
Output is correct |
27 |
Correct |
8 ms |
65112 KB |
Output is correct |
28 |
Correct |
7 ms |
64860 KB |
Output is correct |
29 |
Correct |
8 ms |
64860 KB |
Output is correct |
30 |
Correct |
7 ms |
64964 KB |
Output is correct |
31 |
Correct |
7 ms |
64860 KB |
Output is correct |
32 |
Correct |
7 ms |
64860 KB |
Output is correct |
33 |
Correct |
8 ms |
64860 KB |
Output is correct |
34 |
Correct |
8 ms |
64860 KB |
Output is correct |
35 |
Correct |
7 ms |
64860 KB |
Output is correct |
36 |
Correct |
38 ms |
64952 KB |
Output is correct |
37 |
Correct |
23 ms |
64860 KB |
Output is correct |
38 |
Correct |
14 ms |
64860 KB |
Output is correct |
39 |
Correct |
21 ms |
64860 KB |
Output is correct |
40 |
Correct |
26 ms |
64860 KB |
Output is correct |
41 |
Correct |
15 ms |
64860 KB |
Output is correct |
42 |
Correct |
10 ms |
64912 KB |
Output is correct |
43 |
Correct |
13 ms |
64860 KB |
Output is correct |
44 |
Incorrect |
8 ms |
64860 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |