#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
int main() {
int n, l;
std::cin >> n >> l;
std::vector<int> x(n + 2, 0), t(n + 2, 0);
for (int i = 1; i <= n; ++i) std::cin >> x[i];
for (int i = 1; i <= n; ++i) std::cin >> t[i];
x[n + 1] = l;
std::vector<std::vector<std::vector<std::array<int, 2>>>> dp(
n + 2, std::vector<std::vector<std::array<int, 2>>>(
n + 2, std::vector<std::array<int, 2>>(n + 2)));
constexpr int kInf = 2'000'000'000;
for (int i = 0; i <= n + 1; ++i) {
for (int j = 0; j <= n + 1; ++j) {
for (int k = 0; k <= n + 1; ++k) {
dp[i][j][k][0] = kInf;
dp[i][j][k][1] = kInf;
}
}
}
dp[0][n + 1][0][0] = 0;
dp[0][n + 1][0][1] = 0;
for (int i = 0; i <= n + 1; ++i) {
for (int j = n + 1; j >= 0; --j) {
for (int k = 0; k <= n + 1; ++k) {
if (dp[i][j][k][0] != kInf) {
if (i + 1 < j) {
int g = dp[i][j][k][0] + x[i + 1] - x[i];
if (g <= t[i + 1] && k <= n) {
dp[i + 1][j][k + 1][0] = std::min(dp[i + 1][j][k + 1][0], g);
}
dp[i + 1][j][k][0] = std::min(dp[i + 1][j][k][0], g);
}
if (j - 1 > i) {
int g = dp[i][j][k][0] + l - (x[j - 1] - x[i]);
if (g <= t[j - 1] && k <= n) {
dp[i][j - 1][k + 1][1] = std::min(dp[i][j - 1][k + 1][1], g);
}
dp[i][j - 1][k][1] = std::min(dp[i][j - 1][k][1], g);
}
}
if (dp[i][j][k][1] != kInf) {
if (i + 1 < j) {
int g = dp[i][j][k][1] + l - (x[j] - x[i + 1]);
if (g <= t[i + 1] && k <= n) {
dp[i + 1][j][k + 1][0] = std::min(dp[i + 1][j][k + 1][0], g);
}
dp[i + 1][j][k][0] = std::min(dp[i + 1][j][k][0], g);
}
if (j - 1 > i) {
int g = dp[i][j][k][1] + x[j] - x[j - 1];
if (g <= t[j - 1] && k <= n) {
dp[i][j - 1][k + 1][1] = std::min(dp[i][j - 1][k + 1][1], g);
}
dp[i][j - 1][k][1] = std::min(dp[i][j - 1][k][1], g);
}
}
}
}
}
int ans = 0;
for (int i = 0; i <= n + 1; ++i) {
for (int j = 0; j <= n + 1; ++j) {
for (int k = 0; k <= n + 1; ++k) {
if (dp[i][j][k][0] != kInf) ans = std::max(ans, k);
if (dp[i][j][k][1] != kInf) ans = std::max(ans, k);
}
}
}
std::cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
92 ms |
47992 KB |
Output is correct |
19 |
Correct |
50 ms |
23032 KB |
Output is correct |
20 |
Correct |
23 ms |
9208 KB |
Output is correct |
21 |
Correct |
13 ms |
21112 KB |
Output is correct |
22 |
Correct |
65 ms |
31224 KB |
Output is correct |
23 |
Correct |
20 ms |
7416 KB |
Output is correct |
24 |
Correct |
13 ms |
5240 KB |
Output is correct |
25 |
Correct |
20 ms |
7160 KB |
Output is correct |
26 |
Correct |
7 ms |
2040 KB |
Output is correct |
27 |
Correct |
21 ms |
7672 KB |
Output is correct |
28 |
Correct |
11 ms |
4728 KB |
Output is correct |
29 |
Correct |
20 ms |
7800 KB |
Output is correct |
30 |
Correct |
13 ms |
5624 KB |
Output is correct |
31 |
Correct |
18 ms |
7160 KB |
Output is correct |
32 |
Correct |
9 ms |
3064 KB |
Output is correct |
33 |
Correct |
19 ms |
7160 KB |
Output is correct |
34 |
Correct |
7 ms |
1784 KB |
Output is correct |
35 |
Correct |
15 ms |
6904 KB |
Output is correct |
36 |
Correct |
8 ms |
2552 KB |
Output is correct |
37 |
Correct |
18 ms |
7672 KB |
Output is correct |
38 |
Correct |
10 ms |
3320 KB |
Output is correct |
39 |
Correct |
18 ms |
8184 KB |
Output is correct |
40 |
Correct |
10 ms |
3836 KB |
Output is correct |
41 |
Correct |
140 ms |
65504 KB |
Output is correct |
42 |
Correct |
52 ms |
36600 KB |
Output is correct |
43 |
Correct |
141 ms |
65528 KB |
Output is correct |
44 |
Correct |
53 ms |
36088 KB |
Output is correct |
45 |
Correct |
143 ms |
65656 KB |
Output is correct |
46 |
Correct |
53 ms |
36476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |