#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 205;
int dp[N][N][N][2];
void upd(int &x, int y) {
x = min(x, y);
}
int main () {
owo;
int n, l;
cin >> n >> l;
vector <int> x(n), T(n);
for (int i = 0; i < n; ++i)
cin >> x[i];
for (int i = 0; i < n; ++i)
cin >> T[i];
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k)
dp[i][j][k][0] = dp[i][j][k][1] = 1 << 30;
auto dis = [&](int x, int y) {
int d = abs(y - x);
return min(d, l - d);
};
{
int t = min(x[0], l - x[0]);
dp[1][0][t <= T[0]][0] = t;
}
{
int t = min(x[n - 1], l - x[n - 1]);
dp[0][1][t <= T[n - 1]][1] = t;
}
for (int len = 1; len < n; ++len) for (int l = 0; l <= len; ++l) for (int num = 0; num < n; ++num) {
int r = len - l;
// left to left
if (l && dp[l][r][num][0] != 1 << 30) {
int t = dp[l][r][num][0] + dis(x[l - 1], x[l]);
upd(dp[l + 1][r][num + (t <= T[l])][0], t);
}
// left to right
if (l && dp[l][r][num][0] != 1 << 30) {
int t = dp[l][r][num][0] + dis(x[l - 1], x[n - r - 1]);
upd(dp[l][r + 1][num + (t <= T[n - r - 1])][1], t);
}
// right to left
if (r && dp[l][r][num][1] != 1 << 30) {
int t = dp[l][r][num][1] + dis(x[n - r], x[l]);
upd(dp[l + 1][r][num + (t <= T[l])][0], t);
}
// right to right
if (r && dp[l][r][num][1] != 1 << 30) {
int t = dp[l][r][num][1] + dis(x[n - r], x[n - r - 1]);
upd(dp[l][r + 1][num + (t <= T[n - r - 1])][1], t);
}
}
int ans = 0;
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) {
if (dp[i][j][k][0] < 1 << 30 || dp[i][j][k][1] < 1 << 30)
ans = max(ans, k);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
67660 KB |
Output is correct |
2 |
Correct |
41 ms |
67668 KB |
Output is correct |
3 |
Correct |
41 ms |
67660 KB |
Output is correct |
4 |
Correct |
42 ms |
67720 KB |
Output is correct |
5 |
Correct |
40 ms |
67700 KB |
Output is correct |
6 |
Correct |
40 ms |
67700 KB |
Output is correct |
7 |
Correct |
41 ms |
67780 KB |
Output is correct |
8 |
Correct |
42 ms |
67644 KB |
Output is correct |
9 |
Correct |
50 ms |
67640 KB |
Output is correct |
10 |
Correct |
54 ms |
67684 KB |
Output is correct |
11 |
Correct |
54 ms |
67652 KB |
Output is correct |
12 |
Correct |
53 ms |
67680 KB |
Output is correct |
13 |
Correct |
41 ms |
67732 KB |
Output is correct |
14 |
Correct |
42 ms |
67680 KB |
Output is correct |
15 |
Correct |
41 ms |
67636 KB |
Output is correct |
16 |
Correct |
56 ms |
67736 KB |
Output is correct |
17 |
Correct |
43 ms |
67736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
67660 KB |
Output is correct |
2 |
Correct |
41 ms |
67668 KB |
Output is correct |
3 |
Correct |
41 ms |
67660 KB |
Output is correct |
4 |
Correct |
42 ms |
67720 KB |
Output is correct |
5 |
Correct |
40 ms |
67700 KB |
Output is correct |
6 |
Correct |
40 ms |
67700 KB |
Output is correct |
7 |
Correct |
41 ms |
67780 KB |
Output is correct |
8 |
Correct |
42 ms |
67644 KB |
Output is correct |
9 |
Correct |
50 ms |
67640 KB |
Output is correct |
10 |
Correct |
54 ms |
67684 KB |
Output is correct |
11 |
Correct |
54 ms |
67652 KB |
Output is correct |
12 |
Correct |
53 ms |
67680 KB |
Output is correct |
13 |
Correct |
41 ms |
67732 KB |
Output is correct |
14 |
Correct |
42 ms |
67680 KB |
Output is correct |
15 |
Correct |
41 ms |
67636 KB |
Output is correct |
16 |
Correct |
56 ms |
67736 KB |
Output is correct |
17 |
Correct |
43 ms |
67736 KB |
Output is correct |
18 |
Correct |
42 ms |
67740 KB |
Output is correct |
19 |
Correct |
48 ms |
67736 KB |
Output is correct |
20 |
Correct |
42 ms |
67672 KB |
Output is correct |
21 |
Correct |
49 ms |
67660 KB |
Output is correct |
22 |
Correct |
42 ms |
67660 KB |
Output is correct |
23 |
Correct |
42 ms |
67724 KB |
Output is correct |
24 |
Correct |
55 ms |
67704 KB |
Output is correct |
25 |
Correct |
41 ms |
67660 KB |
Output is correct |
26 |
Correct |
42 ms |
67720 KB |
Output is correct |
27 |
Correct |
43 ms |
67744 KB |
Output is correct |
28 |
Correct |
53 ms |
67728 KB |
Output is correct |
29 |
Correct |
42 ms |
67716 KB |
Output is correct |
30 |
Correct |
57 ms |
67740 KB |
Output is correct |
31 |
Correct |
42 ms |
67632 KB |
Output is correct |
32 |
Correct |
41 ms |
67736 KB |
Output is correct |
33 |
Correct |
44 ms |
67628 KB |
Output is correct |
34 |
Correct |
41 ms |
67660 KB |
Output is correct |
35 |
Correct |
46 ms |
67752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
67660 KB |
Output is correct |
2 |
Correct |
41 ms |
67668 KB |
Output is correct |
3 |
Correct |
41 ms |
67660 KB |
Output is correct |
4 |
Correct |
42 ms |
67720 KB |
Output is correct |
5 |
Correct |
40 ms |
67700 KB |
Output is correct |
6 |
Correct |
40 ms |
67700 KB |
Output is correct |
7 |
Correct |
41 ms |
67780 KB |
Output is correct |
8 |
Correct |
42 ms |
67644 KB |
Output is correct |
9 |
Correct |
50 ms |
67640 KB |
Output is correct |
10 |
Correct |
54 ms |
67684 KB |
Output is correct |
11 |
Correct |
54 ms |
67652 KB |
Output is correct |
12 |
Correct |
53 ms |
67680 KB |
Output is correct |
13 |
Correct |
41 ms |
67732 KB |
Output is correct |
14 |
Correct |
42 ms |
67680 KB |
Output is correct |
15 |
Correct |
41 ms |
67636 KB |
Output is correct |
16 |
Correct |
56 ms |
67736 KB |
Output is correct |
17 |
Correct |
43 ms |
67736 KB |
Output is correct |
18 |
Correct |
75 ms |
67744 KB |
Output is correct |
19 |
Correct |
64 ms |
67740 KB |
Output is correct |
20 |
Correct |
57 ms |
67744 KB |
Output is correct |
21 |
Correct |
58 ms |
67736 KB |
Output is correct |
22 |
Correct |
66 ms |
67732 KB |
Output is correct |
23 |
Correct |
48 ms |
67736 KB |
Output is correct |
24 |
Correct |
45 ms |
67648 KB |
Output is correct |
25 |
Correct |
51 ms |
67736 KB |
Output is correct |
26 |
Correct |
46 ms |
67652 KB |
Output is correct |
27 |
Correct |
53 ms |
67668 KB |
Output is correct |
28 |
Correct |
49 ms |
67744 KB |
Output is correct |
29 |
Correct |
48 ms |
67660 KB |
Output is correct |
30 |
Correct |
47 ms |
67684 KB |
Output is correct |
31 |
Correct |
48 ms |
67744 KB |
Output is correct |
32 |
Correct |
43 ms |
67660 KB |
Output is correct |
33 |
Correct |
62 ms |
67660 KB |
Output is correct |
34 |
Correct |
57 ms |
67652 KB |
Output is correct |
35 |
Correct |
44 ms |
67736 KB |
Output is correct |
36 |
Correct |
43 ms |
67684 KB |
Output is correct |
37 |
Correct |
50 ms |
67648 KB |
Output is correct |
38 |
Correct |
43 ms |
67740 KB |
Output is correct |
39 |
Correct |
48 ms |
67720 KB |
Output is correct |
40 |
Correct |
46 ms |
67736 KB |
Output is correct |
41 |
Correct |
106 ms |
67744 KB |
Output is correct |
42 |
Correct |
51 ms |
67656 KB |
Output is correct |
43 |
Correct |
94 ms |
67736 KB |
Output is correct |
44 |
Correct |
48 ms |
67732 KB |
Output is correct |
45 |
Correct |
96 ms |
67624 KB |
Output is correct |
46 |
Correct |
51 ms |
67640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
67660 KB |
Output is correct |
2 |
Correct |
41 ms |
67668 KB |
Output is correct |
3 |
Correct |
41 ms |
67660 KB |
Output is correct |
4 |
Correct |
42 ms |
67720 KB |
Output is correct |
5 |
Correct |
40 ms |
67700 KB |
Output is correct |
6 |
Correct |
40 ms |
67700 KB |
Output is correct |
7 |
Correct |
41 ms |
67780 KB |
Output is correct |
8 |
Correct |
42 ms |
67644 KB |
Output is correct |
9 |
Correct |
50 ms |
67640 KB |
Output is correct |
10 |
Correct |
54 ms |
67684 KB |
Output is correct |
11 |
Correct |
54 ms |
67652 KB |
Output is correct |
12 |
Correct |
53 ms |
67680 KB |
Output is correct |
13 |
Correct |
41 ms |
67732 KB |
Output is correct |
14 |
Correct |
42 ms |
67680 KB |
Output is correct |
15 |
Correct |
41 ms |
67636 KB |
Output is correct |
16 |
Correct |
56 ms |
67736 KB |
Output is correct |
17 |
Correct |
43 ms |
67736 KB |
Output is correct |
18 |
Correct |
42 ms |
67740 KB |
Output is correct |
19 |
Correct |
48 ms |
67736 KB |
Output is correct |
20 |
Correct |
42 ms |
67672 KB |
Output is correct |
21 |
Correct |
49 ms |
67660 KB |
Output is correct |
22 |
Correct |
42 ms |
67660 KB |
Output is correct |
23 |
Correct |
42 ms |
67724 KB |
Output is correct |
24 |
Correct |
55 ms |
67704 KB |
Output is correct |
25 |
Correct |
41 ms |
67660 KB |
Output is correct |
26 |
Correct |
42 ms |
67720 KB |
Output is correct |
27 |
Correct |
43 ms |
67744 KB |
Output is correct |
28 |
Correct |
53 ms |
67728 KB |
Output is correct |
29 |
Correct |
42 ms |
67716 KB |
Output is correct |
30 |
Correct |
57 ms |
67740 KB |
Output is correct |
31 |
Correct |
42 ms |
67632 KB |
Output is correct |
32 |
Correct |
41 ms |
67736 KB |
Output is correct |
33 |
Correct |
44 ms |
67628 KB |
Output is correct |
34 |
Correct |
41 ms |
67660 KB |
Output is correct |
35 |
Correct |
46 ms |
67752 KB |
Output is correct |
36 |
Correct |
75 ms |
67744 KB |
Output is correct |
37 |
Correct |
64 ms |
67740 KB |
Output is correct |
38 |
Correct |
57 ms |
67744 KB |
Output is correct |
39 |
Correct |
58 ms |
67736 KB |
Output is correct |
40 |
Correct |
66 ms |
67732 KB |
Output is correct |
41 |
Correct |
48 ms |
67736 KB |
Output is correct |
42 |
Correct |
45 ms |
67648 KB |
Output is correct |
43 |
Correct |
51 ms |
67736 KB |
Output is correct |
44 |
Correct |
46 ms |
67652 KB |
Output is correct |
45 |
Correct |
53 ms |
67668 KB |
Output is correct |
46 |
Correct |
49 ms |
67744 KB |
Output is correct |
47 |
Correct |
48 ms |
67660 KB |
Output is correct |
48 |
Correct |
47 ms |
67684 KB |
Output is correct |
49 |
Correct |
48 ms |
67744 KB |
Output is correct |
50 |
Correct |
43 ms |
67660 KB |
Output is correct |
51 |
Correct |
62 ms |
67660 KB |
Output is correct |
52 |
Correct |
57 ms |
67652 KB |
Output is correct |
53 |
Correct |
44 ms |
67736 KB |
Output is correct |
54 |
Correct |
43 ms |
67684 KB |
Output is correct |
55 |
Correct |
50 ms |
67648 KB |
Output is correct |
56 |
Correct |
43 ms |
67740 KB |
Output is correct |
57 |
Correct |
48 ms |
67720 KB |
Output is correct |
58 |
Correct |
46 ms |
67736 KB |
Output is correct |
59 |
Correct |
106 ms |
67744 KB |
Output is correct |
60 |
Correct |
51 ms |
67656 KB |
Output is correct |
61 |
Correct |
94 ms |
67736 KB |
Output is correct |
62 |
Correct |
48 ms |
67732 KB |
Output is correct |
63 |
Correct |
96 ms |
67624 KB |
Output is correct |
64 |
Correct |
51 ms |
67640 KB |
Output is correct |
65 |
Correct |
77 ms |
67664 KB |
Output is correct |
66 |
Correct |
56 ms |
67664 KB |
Output is correct |
67 |
Correct |
56 ms |
67740 KB |
Output is correct |
68 |
Correct |
53 ms |
67660 KB |
Output is correct |
69 |
Correct |
61 ms |
67744 KB |
Output is correct |
70 |
Correct |
73 ms |
67712 KB |
Output is correct |
71 |
Correct |
56 ms |
67748 KB |
Output is correct |
72 |
Correct |
68 ms |
67700 KB |
Output is correct |
73 |
Correct |
68 ms |
67744 KB |
Output is correct |
74 |
Correct |
64 ms |
67628 KB |
Output is correct |
75 |
Correct |
54 ms |
67740 KB |
Output is correct |
76 |
Correct |
99 ms |
67660 KB |
Output is correct |
77 |
Correct |
56 ms |
67660 KB |
Output is correct |
78 |
Correct |
80 ms |
67752 KB |
Output is correct |
79 |
Correct |
55 ms |
67752 KB |
Output is correct |
80 |
Correct |
92 ms |
67624 KB |
Output is correct |
81 |
Correct |
56 ms |
67636 KB |
Output is correct |
82 |
Correct |
68 ms |
67744 KB |
Output is correct |
83 |
Correct |
57 ms |
67744 KB |
Output is correct |
84 |
Correct |
71 ms |
67656 KB |
Output is correct |
85 |
Correct |
78 ms |
67748 KB |
Output is correct |
86 |
Correct |
73 ms |
67624 KB |
Output is correct |
87 |
Correct |
52 ms |
67660 KB |
Output is correct |
88 |
Correct |
69 ms |
67748 KB |
Output is correct |
89 |
Correct |
57 ms |
67716 KB |
Output is correct |
90 |
Correct |
69 ms |
67636 KB |
Output is correct |
91 |
Correct |
79 ms |
67768 KB |
Output is correct |
92 |
Correct |
54 ms |
67620 KB |
Output is correct |
93 |
Correct |
52 ms |
67676 KB |
Output is correct |