#include <bits/stdc++.h>
#define int long long
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a, I = b; i <= I; i++)
using namespace std;
using pii = pair<int, int>;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) { cout << a << " "; dbg(b...); }
void ent() { cout << "\n"; }
const int INF = 1e17;
const int N = 205;
int a[N], t[N];
int dp[2][N][N][N];
signed main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
IO;
int n, tot;
cin >> n >> tot;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> t[i];
int ans = 0;
fill(&dp[0][0][0][0], &dp[0][0][0][0] + 2 * N * N * N, INF);
dp[0][0][0][n] = 0;
for (int i = 0; i <= n; i++) {
for (int r = n; r >= 1; r--) {
// Left : 0
for (int l = 1; l <= r; l++) {
int ti;
if (i) {
ti = dp[0][i - 1][l - 1][r] + (a[l] - a[l - 1]);
if (ti <= t[l])
dp[0][i][l][r] = min(dp[0][i][l][r], ti);
if (r + 1 <= n) {
ti = dp[1][i - 1][l][r + 1] + (tot - a[r + 1] + a[l] - 0);
if (ti <= t[l])
dp[0][i][l][r] = min(dp[0][i][l][r], ti);
}
}
ti = dp[0][i][l - 1][r] + (a[l] - a[l - 1]);
dp[0][i][l][r] = min(dp[0][i][l][r], ti);
if (r + 1 <= n) {
ti = dp[1][i][l][r + 1] + (tot - a[r + 1] + a[l] - 0);
dp[0][i][l][r] = min(dp[0][i][l][r], ti);
}
if (dp[0][i][l][r] < INF) {
// dbg(0, i, l, r, ':', dp[0][i][l][r]), ent();
ans = max(ans, i);
}
}
// Right : 1
for (int l = 1; l <= r; l++) {
int ti;
if (i) {
ti = dp[0][i - 1][l - 1][r] + (a[l - 1] - 0 + tot - a[r]);
if (ti <= t[r])
dp[1][i][l][r] = min(dp[1][i][l][r], ti);
ti = dp[1][i - 1][l][r + 1] + (a[r + 1] - a[r]);
if (ti <= t[r])
dp[1][i][l][r] = min(dp[1][i][l][r], ti);
}
ti = dp[0][i][l - 1][r] + (a[l - 1] - 0 + tot - a[r]);
dp[1][i][l][r] = min(dp[1][i][l][r], ti);
if (r + 1 <= n) {
ti = dp[1][i][l][r + 1] + (a[r + 1] - a[r]);
dp[1][i][l][r] = min(dp[1][i][l][r], ti);
}
if (dp[1][i][l][r] < INF) {
// dbg(1, i, l, r, ':', dp[1][i][l][r]), ent();
ans = max(ans, i);
}
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
135248 KB |
Output is correct |
2 |
Correct |
19 ms |
135260 KB |
Output is correct |
3 |
Correct |
21 ms |
135260 KB |
Output is correct |
4 |
Correct |
20 ms |
135252 KB |
Output is correct |
5 |
Correct |
20 ms |
135236 KB |
Output is correct |
6 |
Correct |
20 ms |
135160 KB |
Output is correct |
7 |
Correct |
20 ms |
135260 KB |
Output is correct |
8 |
Correct |
20 ms |
135260 KB |
Output is correct |
9 |
Correct |
21 ms |
135516 KB |
Output is correct |
10 |
Correct |
22 ms |
135252 KB |
Output is correct |
11 |
Correct |
22 ms |
135252 KB |
Output is correct |
12 |
Correct |
20 ms |
135260 KB |
Output is correct |
13 |
Correct |
20 ms |
135248 KB |
Output is correct |
14 |
Correct |
20 ms |
135260 KB |
Output is correct |
15 |
Correct |
19 ms |
135152 KB |
Output is correct |
16 |
Correct |
21 ms |
135248 KB |
Output is correct |
17 |
Correct |
21 ms |
135228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
135248 KB |
Output is correct |
2 |
Correct |
19 ms |
135260 KB |
Output is correct |
3 |
Correct |
21 ms |
135260 KB |
Output is correct |
4 |
Correct |
20 ms |
135252 KB |
Output is correct |
5 |
Correct |
20 ms |
135236 KB |
Output is correct |
6 |
Correct |
20 ms |
135160 KB |
Output is correct |
7 |
Correct |
20 ms |
135260 KB |
Output is correct |
8 |
Correct |
20 ms |
135260 KB |
Output is correct |
9 |
Correct |
21 ms |
135516 KB |
Output is correct |
10 |
Correct |
22 ms |
135252 KB |
Output is correct |
11 |
Correct |
22 ms |
135252 KB |
Output is correct |
12 |
Correct |
20 ms |
135260 KB |
Output is correct |
13 |
Correct |
20 ms |
135248 KB |
Output is correct |
14 |
Correct |
20 ms |
135260 KB |
Output is correct |
15 |
Correct |
19 ms |
135152 KB |
Output is correct |
16 |
Correct |
21 ms |
135248 KB |
Output is correct |
17 |
Correct |
21 ms |
135228 KB |
Output is correct |
18 |
Correct |
20 ms |
135304 KB |
Output is correct |
19 |
Correct |
20 ms |
135256 KB |
Output is correct |
20 |
Correct |
21 ms |
135252 KB |
Output is correct |
21 |
Correct |
22 ms |
135260 KB |
Output is correct |
22 |
Correct |
20 ms |
135256 KB |
Output is correct |
23 |
Correct |
20 ms |
135284 KB |
Output is correct |
24 |
Correct |
20 ms |
135300 KB |
Output is correct |
25 |
Correct |
20 ms |
135292 KB |
Output is correct |
26 |
Correct |
20 ms |
135260 KB |
Output is correct |
27 |
Correct |
24 ms |
135260 KB |
Output is correct |
28 |
Correct |
21 ms |
135260 KB |
Output is correct |
29 |
Correct |
23 ms |
135180 KB |
Output is correct |
30 |
Correct |
22 ms |
135260 KB |
Output is correct |
31 |
Correct |
20 ms |
135212 KB |
Output is correct |
32 |
Correct |
20 ms |
135228 KB |
Output is correct |
33 |
Correct |
20 ms |
135256 KB |
Output is correct |
34 |
Correct |
20 ms |
135284 KB |
Output is correct |
35 |
Correct |
20 ms |
135260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
135248 KB |
Output is correct |
2 |
Correct |
19 ms |
135260 KB |
Output is correct |
3 |
Correct |
21 ms |
135260 KB |
Output is correct |
4 |
Correct |
20 ms |
135252 KB |
Output is correct |
5 |
Correct |
20 ms |
135236 KB |
Output is correct |
6 |
Correct |
20 ms |
135160 KB |
Output is correct |
7 |
Correct |
20 ms |
135260 KB |
Output is correct |
8 |
Correct |
20 ms |
135260 KB |
Output is correct |
9 |
Correct |
21 ms |
135516 KB |
Output is correct |
10 |
Correct |
22 ms |
135252 KB |
Output is correct |
11 |
Correct |
22 ms |
135252 KB |
Output is correct |
12 |
Correct |
20 ms |
135260 KB |
Output is correct |
13 |
Correct |
20 ms |
135248 KB |
Output is correct |
14 |
Correct |
20 ms |
135260 KB |
Output is correct |
15 |
Correct |
19 ms |
135152 KB |
Output is correct |
16 |
Correct |
21 ms |
135248 KB |
Output is correct |
17 |
Correct |
21 ms |
135228 KB |
Output is correct |
18 |
Correct |
72 ms |
135308 KB |
Output is correct |
19 |
Correct |
48 ms |
135260 KB |
Output is correct |
20 |
Correct |
30 ms |
135100 KB |
Output is correct |
21 |
Correct |
47 ms |
135252 KB |
Output is correct |
22 |
Correct |
54 ms |
135376 KB |
Output is correct |
23 |
Correct |
28 ms |
135260 KB |
Output is correct |
24 |
Correct |
25 ms |
135260 KB |
Output is correct |
25 |
Correct |
28 ms |
135248 KB |
Output is correct |
26 |
Correct |
22 ms |
135248 KB |
Output is correct |
27 |
Correct |
30 ms |
135196 KB |
Output is correct |
28 |
Correct |
28 ms |
135292 KB |
Output is correct |
29 |
Correct |
28 ms |
135252 KB |
Output is correct |
30 |
Correct |
26 ms |
135264 KB |
Output is correct |
31 |
Correct |
28 ms |
135260 KB |
Output is correct |
32 |
Correct |
24 ms |
135268 KB |
Output is correct |
33 |
Correct |
28 ms |
135264 KB |
Output is correct |
34 |
Correct |
22 ms |
135264 KB |
Output is correct |
35 |
Correct |
28 ms |
135264 KB |
Output is correct |
36 |
Correct |
23 ms |
135268 KB |
Output is correct |
37 |
Correct |
28 ms |
135268 KB |
Output is correct |
38 |
Correct |
24 ms |
135268 KB |
Output is correct |
39 |
Correct |
29 ms |
135260 KB |
Output is correct |
40 |
Correct |
24 ms |
135268 KB |
Output is correct |
41 |
Correct |
91 ms |
135268 KB |
Output is correct |
42 |
Correct |
57 ms |
135260 KB |
Output is correct |
43 |
Correct |
99 ms |
135264 KB |
Output is correct |
44 |
Correct |
60 ms |
135504 KB |
Output is correct |
45 |
Correct |
97 ms |
135312 KB |
Output is correct |
46 |
Correct |
56 ms |
135252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
135248 KB |
Output is correct |
2 |
Correct |
19 ms |
135260 KB |
Output is correct |
3 |
Correct |
21 ms |
135260 KB |
Output is correct |
4 |
Correct |
20 ms |
135252 KB |
Output is correct |
5 |
Correct |
20 ms |
135236 KB |
Output is correct |
6 |
Correct |
20 ms |
135160 KB |
Output is correct |
7 |
Correct |
20 ms |
135260 KB |
Output is correct |
8 |
Correct |
20 ms |
135260 KB |
Output is correct |
9 |
Correct |
21 ms |
135516 KB |
Output is correct |
10 |
Correct |
22 ms |
135252 KB |
Output is correct |
11 |
Correct |
22 ms |
135252 KB |
Output is correct |
12 |
Correct |
20 ms |
135260 KB |
Output is correct |
13 |
Correct |
20 ms |
135248 KB |
Output is correct |
14 |
Correct |
20 ms |
135260 KB |
Output is correct |
15 |
Correct |
19 ms |
135152 KB |
Output is correct |
16 |
Correct |
21 ms |
135248 KB |
Output is correct |
17 |
Correct |
21 ms |
135228 KB |
Output is correct |
18 |
Correct |
20 ms |
135304 KB |
Output is correct |
19 |
Correct |
20 ms |
135256 KB |
Output is correct |
20 |
Correct |
21 ms |
135252 KB |
Output is correct |
21 |
Correct |
22 ms |
135260 KB |
Output is correct |
22 |
Correct |
20 ms |
135256 KB |
Output is correct |
23 |
Correct |
20 ms |
135284 KB |
Output is correct |
24 |
Correct |
20 ms |
135300 KB |
Output is correct |
25 |
Correct |
20 ms |
135292 KB |
Output is correct |
26 |
Correct |
20 ms |
135260 KB |
Output is correct |
27 |
Correct |
24 ms |
135260 KB |
Output is correct |
28 |
Correct |
21 ms |
135260 KB |
Output is correct |
29 |
Correct |
23 ms |
135180 KB |
Output is correct |
30 |
Correct |
22 ms |
135260 KB |
Output is correct |
31 |
Correct |
20 ms |
135212 KB |
Output is correct |
32 |
Correct |
20 ms |
135228 KB |
Output is correct |
33 |
Correct |
20 ms |
135256 KB |
Output is correct |
34 |
Correct |
20 ms |
135284 KB |
Output is correct |
35 |
Correct |
20 ms |
135260 KB |
Output is correct |
36 |
Correct |
72 ms |
135308 KB |
Output is correct |
37 |
Correct |
48 ms |
135260 KB |
Output is correct |
38 |
Correct |
30 ms |
135100 KB |
Output is correct |
39 |
Correct |
47 ms |
135252 KB |
Output is correct |
40 |
Correct |
54 ms |
135376 KB |
Output is correct |
41 |
Correct |
28 ms |
135260 KB |
Output is correct |
42 |
Correct |
25 ms |
135260 KB |
Output is correct |
43 |
Correct |
28 ms |
135248 KB |
Output is correct |
44 |
Correct |
22 ms |
135248 KB |
Output is correct |
45 |
Correct |
30 ms |
135196 KB |
Output is correct |
46 |
Correct |
28 ms |
135292 KB |
Output is correct |
47 |
Correct |
28 ms |
135252 KB |
Output is correct |
48 |
Correct |
26 ms |
135264 KB |
Output is correct |
49 |
Correct |
28 ms |
135260 KB |
Output is correct |
50 |
Correct |
24 ms |
135268 KB |
Output is correct |
51 |
Correct |
28 ms |
135264 KB |
Output is correct |
52 |
Correct |
22 ms |
135264 KB |
Output is correct |
53 |
Correct |
28 ms |
135264 KB |
Output is correct |
54 |
Correct |
23 ms |
135268 KB |
Output is correct |
55 |
Correct |
28 ms |
135268 KB |
Output is correct |
56 |
Correct |
24 ms |
135268 KB |
Output is correct |
57 |
Correct |
29 ms |
135260 KB |
Output is correct |
58 |
Correct |
24 ms |
135268 KB |
Output is correct |
59 |
Correct |
91 ms |
135268 KB |
Output is correct |
60 |
Correct |
57 ms |
135260 KB |
Output is correct |
61 |
Correct |
99 ms |
135264 KB |
Output is correct |
62 |
Correct |
60 ms |
135504 KB |
Output is correct |
63 |
Correct |
97 ms |
135312 KB |
Output is correct |
64 |
Correct |
56 ms |
135252 KB |
Output is correct |
65 |
Correct |
80 ms |
135260 KB |
Output is correct |
66 |
Correct |
71 ms |
135252 KB |
Output is correct |
67 |
Correct |
69 ms |
135260 KB |
Output is correct |
68 |
Correct |
63 ms |
135316 KB |
Output is correct |
69 |
Correct |
81 ms |
135316 KB |
Output is correct |
70 |
Correct |
84 ms |
135252 KB |
Output is correct |
71 |
Correct |
87 ms |
135504 KB |
Output is correct |
72 |
Correct |
84 ms |
135316 KB |
Output is correct |
73 |
Correct |
75 ms |
135260 KB |
Output is correct |
74 |
Correct |
70 ms |
135312 KB |
Output is correct |
75 |
Correct |
75 ms |
135260 KB |
Output is correct |
76 |
Correct |
91 ms |
135656 KB |
Output is correct |
77 |
Correct |
103 ms |
135248 KB |
Output is correct |
78 |
Correct |
78 ms |
135252 KB |
Output is correct |
79 |
Correct |
79 ms |
135252 KB |
Output is correct |
80 |
Correct |
101 ms |
135228 KB |
Output is correct |
81 |
Correct |
83 ms |
135500 KB |
Output is correct |
82 |
Correct |
82 ms |
135316 KB |
Output is correct |
83 |
Correct |
104 ms |
135184 KB |
Output is correct |
84 |
Correct |
90 ms |
135260 KB |
Output is correct |
85 |
Correct |
95 ms |
135400 KB |
Output is correct |
86 |
Correct |
93 ms |
135304 KB |
Output is correct |
87 |
Correct |
83 ms |
135312 KB |
Output is correct |
88 |
Correct |
110 ms |
135252 KB |
Output is correct |
89 |
Correct |
107 ms |
135316 KB |
Output is correct |
90 |
Correct |
85 ms |
135252 KB |
Output is correct |
91 |
Correct |
120 ms |
135320 KB |
Output is correct |
92 |
Correct |
107 ms |
135196 KB |
Output is correct |
93 |
Correct |
100 ms |
135260 KB |
Output is correct |