#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int MAXN = 228;
int n, l;
ll x[MAXN], t[MAXN];
ll dp[MAXN][MAXN][2][MAXN];
int dist(int i, int j) {
return min(abs(x[i] - x[j]), l - abs(x[i] - x[j]));
}
ll solve(int l, int r, int side, int cnt) {
if (cnt == 0) {
return (1LL << 60);
}
if (l > r) {
return -(1LL << 60);
}
if (dp[l][r][side][cnt] != -1) {
return dp[l][r][side][cnt];
}
int pos;
if (side == 0) {
pos = l - 1;
} else {
pos = r + 1;
}
ll ans = -(1LL << 60);
chkmax(ans, solve(l + 1, r, 0, cnt) - dist(l, pos));
chkmax(ans, min(t[l], solve(l + 1, r, 0, cnt - 1)) - dist(l, pos));
chkmax(ans, solve(l, r - 1, 1, cnt) - dist(r, pos));
chkmax(ans, min(t[r], solve(l, r - 1, 1, cnt - 1)) - dist(r, pos));
dp[l][r][side][cnt] = ans;
return dp[l][r][side][cnt];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
cin >> n >> l;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
for (int i = 0; i < n; i++) {
cin >> t[i];
}
memset(dp, -1, sizeof(dp));
ll sol = 0;
for (int i = 0; i <= n; i++) {
if (solve(0, n - 1, 1, i) >= 0) {
sol = i;
}
}
cout << sol << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
185884 KB |
Output is correct |
2 |
Correct |
61 ms |
185940 KB |
Output is correct |
3 |
Correct |
60 ms |
185936 KB |
Output is correct |
4 |
Correct |
61 ms |
185940 KB |
Output is correct |
5 |
Correct |
60 ms |
185940 KB |
Output is correct |
6 |
Correct |
61 ms |
185940 KB |
Output is correct |
7 |
Correct |
60 ms |
185940 KB |
Output is correct |
8 |
Correct |
62 ms |
185940 KB |
Output is correct |
9 |
Correct |
60 ms |
185972 KB |
Output is correct |
10 |
Correct |
61 ms |
186124 KB |
Output is correct |
11 |
Correct |
71 ms |
185944 KB |
Output is correct |
12 |
Correct |
59 ms |
185984 KB |
Output is correct |
13 |
Correct |
61 ms |
185940 KB |
Output is correct |
14 |
Correct |
60 ms |
185960 KB |
Output is correct |
15 |
Correct |
64 ms |
186328 KB |
Output is correct |
16 |
Correct |
61 ms |
185944 KB |
Output is correct |
17 |
Correct |
60 ms |
185940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
185884 KB |
Output is correct |
2 |
Correct |
61 ms |
185940 KB |
Output is correct |
3 |
Correct |
60 ms |
185936 KB |
Output is correct |
4 |
Correct |
61 ms |
185940 KB |
Output is correct |
5 |
Correct |
60 ms |
185940 KB |
Output is correct |
6 |
Correct |
61 ms |
185940 KB |
Output is correct |
7 |
Correct |
60 ms |
185940 KB |
Output is correct |
8 |
Correct |
62 ms |
185940 KB |
Output is correct |
9 |
Correct |
60 ms |
185972 KB |
Output is correct |
10 |
Correct |
61 ms |
186124 KB |
Output is correct |
11 |
Correct |
71 ms |
185944 KB |
Output is correct |
12 |
Correct |
59 ms |
185984 KB |
Output is correct |
13 |
Correct |
61 ms |
185940 KB |
Output is correct |
14 |
Correct |
60 ms |
185960 KB |
Output is correct |
15 |
Correct |
64 ms |
186328 KB |
Output is correct |
16 |
Correct |
61 ms |
185944 KB |
Output is correct |
17 |
Correct |
60 ms |
185940 KB |
Output is correct |
18 |
Correct |
61 ms |
185944 KB |
Output is correct |
19 |
Correct |
61 ms |
185764 KB |
Output is correct |
20 |
Correct |
62 ms |
185940 KB |
Output is correct |
21 |
Correct |
59 ms |
185960 KB |
Output is correct |
22 |
Correct |
60 ms |
185828 KB |
Output is correct |
23 |
Correct |
60 ms |
185940 KB |
Output is correct |
24 |
Correct |
60 ms |
185936 KB |
Output is correct |
25 |
Correct |
60 ms |
185980 KB |
Output is correct |
26 |
Correct |
62 ms |
185940 KB |
Output is correct |
27 |
Correct |
62 ms |
185880 KB |
Output is correct |
28 |
Correct |
61 ms |
185784 KB |
Output is correct |
29 |
Correct |
62 ms |
185832 KB |
Output is correct |
30 |
Correct |
60 ms |
185936 KB |
Output is correct |
31 |
Correct |
60 ms |
185940 KB |
Output is correct |
32 |
Correct |
60 ms |
185792 KB |
Output is correct |
33 |
Correct |
70 ms |
185956 KB |
Output is correct |
34 |
Correct |
62 ms |
185808 KB |
Output is correct |
35 |
Correct |
60 ms |
185988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
185884 KB |
Output is correct |
2 |
Correct |
61 ms |
185940 KB |
Output is correct |
3 |
Correct |
60 ms |
185936 KB |
Output is correct |
4 |
Correct |
61 ms |
185940 KB |
Output is correct |
5 |
Correct |
60 ms |
185940 KB |
Output is correct |
6 |
Correct |
61 ms |
185940 KB |
Output is correct |
7 |
Correct |
60 ms |
185940 KB |
Output is correct |
8 |
Correct |
62 ms |
185940 KB |
Output is correct |
9 |
Correct |
60 ms |
185972 KB |
Output is correct |
10 |
Correct |
61 ms |
186124 KB |
Output is correct |
11 |
Correct |
71 ms |
185944 KB |
Output is correct |
12 |
Correct |
59 ms |
185984 KB |
Output is correct |
13 |
Correct |
61 ms |
185940 KB |
Output is correct |
14 |
Correct |
60 ms |
185960 KB |
Output is correct |
15 |
Correct |
64 ms |
186328 KB |
Output is correct |
16 |
Correct |
61 ms |
185944 KB |
Output is correct |
17 |
Correct |
60 ms |
185940 KB |
Output is correct |
18 |
Correct |
198 ms |
186040 KB |
Output is correct |
19 |
Correct |
124 ms |
186012 KB |
Output is correct |
20 |
Correct |
84 ms |
185884 KB |
Output is correct |
21 |
Correct |
118 ms |
186004 KB |
Output is correct |
22 |
Correct |
142 ms |
186300 KB |
Output is correct |
23 |
Correct |
79 ms |
185844 KB |
Output is correct |
24 |
Correct |
74 ms |
185876 KB |
Output is correct |
25 |
Correct |
76 ms |
185936 KB |
Output is correct |
26 |
Correct |
64 ms |
185940 KB |
Output is correct |
27 |
Correct |
80 ms |
185936 KB |
Output is correct |
28 |
Correct |
69 ms |
185940 KB |
Output is correct |
29 |
Correct |
77 ms |
185800 KB |
Output is correct |
30 |
Correct |
76 ms |
185936 KB |
Output is correct |
31 |
Correct |
77 ms |
185840 KB |
Output is correct |
32 |
Correct |
66 ms |
185916 KB |
Output is correct |
33 |
Correct |
77 ms |
185940 KB |
Output is correct |
34 |
Correct |
63 ms |
185936 KB |
Output is correct |
35 |
Correct |
74 ms |
185944 KB |
Output is correct |
36 |
Correct |
64 ms |
185940 KB |
Output is correct |
37 |
Correct |
83 ms |
186056 KB |
Output is correct |
38 |
Correct |
65 ms |
185936 KB |
Output is correct |
39 |
Correct |
81 ms |
185936 KB |
Output is correct |
40 |
Correct |
67 ms |
185948 KB |
Output is correct |
41 |
Correct |
253 ms |
186192 KB |
Output is correct |
42 |
Correct |
165 ms |
186008 KB |
Output is correct |
43 |
Correct |
250 ms |
185936 KB |
Output is correct |
44 |
Correct |
170 ms |
186192 KB |
Output is correct |
45 |
Correct |
229 ms |
186012 KB |
Output is correct |
46 |
Correct |
164 ms |
186008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
185884 KB |
Output is correct |
2 |
Correct |
61 ms |
185940 KB |
Output is correct |
3 |
Correct |
60 ms |
185936 KB |
Output is correct |
4 |
Correct |
61 ms |
185940 KB |
Output is correct |
5 |
Correct |
60 ms |
185940 KB |
Output is correct |
6 |
Correct |
61 ms |
185940 KB |
Output is correct |
7 |
Correct |
60 ms |
185940 KB |
Output is correct |
8 |
Correct |
62 ms |
185940 KB |
Output is correct |
9 |
Correct |
60 ms |
185972 KB |
Output is correct |
10 |
Correct |
61 ms |
186124 KB |
Output is correct |
11 |
Correct |
71 ms |
185944 KB |
Output is correct |
12 |
Correct |
59 ms |
185984 KB |
Output is correct |
13 |
Correct |
61 ms |
185940 KB |
Output is correct |
14 |
Correct |
60 ms |
185960 KB |
Output is correct |
15 |
Correct |
64 ms |
186328 KB |
Output is correct |
16 |
Correct |
61 ms |
185944 KB |
Output is correct |
17 |
Correct |
60 ms |
185940 KB |
Output is correct |
18 |
Correct |
61 ms |
185944 KB |
Output is correct |
19 |
Correct |
61 ms |
185764 KB |
Output is correct |
20 |
Correct |
62 ms |
185940 KB |
Output is correct |
21 |
Correct |
59 ms |
185960 KB |
Output is correct |
22 |
Correct |
60 ms |
185828 KB |
Output is correct |
23 |
Correct |
60 ms |
185940 KB |
Output is correct |
24 |
Correct |
60 ms |
185936 KB |
Output is correct |
25 |
Correct |
60 ms |
185980 KB |
Output is correct |
26 |
Correct |
62 ms |
185940 KB |
Output is correct |
27 |
Correct |
62 ms |
185880 KB |
Output is correct |
28 |
Correct |
61 ms |
185784 KB |
Output is correct |
29 |
Correct |
62 ms |
185832 KB |
Output is correct |
30 |
Correct |
60 ms |
185936 KB |
Output is correct |
31 |
Correct |
60 ms |
185940 KB |
Output is correct |
32 |
Correct |
60 ms |
185792 KB |
Output is correct |
33 |
Correct |
70 ms |
185956 KB |
Output is correct |
34 |
Correct |
62 ms |
185808 KB |
Output is correct |
35 |
Correct |
60 ms |
185988 KB |
Output is correct |
36 |
Correct |
198 ms |
186040 KB |
Output is correct |
37 |
Correct |
124 ms |
186012 KB |
Output is correct |
38 |
Correct |
84 ms |
185884 KB |
Output is correct |
39 |
Correct |
118 ms |
186004 KB |
Output is correct |
40 |
Correct |
142 ms |
186300 KB |
Output is correct |
41 |
Correct |
79 ms |
185844 KB |
Output is correct |
42 |
Correct |
74 ms |
185876 KB |
Output is correct |
43 |
Correct |
76 ms |
185936 KB |
Output is correct |
44 |
Correct |
64 ms |
185940 KB |
Output is correct |
45 |
Correct |
80 ms |
185936 KB |
Output is correct |
46 |
Correct |
69 ms |
185940 KB |
Output is correct |
47 |
Correct |
77 ms |
185800 KB |
Output is correct |
48 |
Correct |
76 ms |
185936 KB |
Output is correct |
49 |
Correct |
77 ms |
185840 KB |
Output is correct |
50 |
Correct |
66 ms |
185916 KB |
Output is correct |
51 |
Correct |
77 ms |
185940 KB |
Output is correct |
52 |
Correct |
63 ms |
185936 KB |
Output is correct |
53 |
Correct |
74 ms |
185944 KB |
Output is correct |
54 |
Correct |
64 ms |
185940 KB |
Output is correct |
55 |
Correct |
83 ms |
186056 KB |
Output is correct |
56 |
Correct |
65 ms |
185936 KB |
Output is correct |
57 |
Correct |
81 ms |
185936 KB |
Output is correct |
58 |
Correct |
67 ms |
185948 KB |
Output is correct |
59 |
Correct |
253 ms |
186192 KB |
Output is correct |
60 |
Correct |
165 ms |
186008 KB |
Output is correct |
61 |
Correct |
250 ms |
185936 KB |
Output is correct |
62 |
Correct |
170 ms |
186192 KB |
Output is correct |
63 |
Correct |
229 ms |
186012 KB |
Output is correct |
64 |
Correct |
164 ms |
186008 KB |
Output is correct |
65 |
Correct |
210 ms |
185944 KB |
Output is correct |
66 |
Correct |
193 ms |
185764 KB |
Output is correct |
67 |
Correct |
169 ms |
185888 KB |
Output is correct |
68 |
Correct |
170 ms |
186012 KB |
Output is correct |
69 |
Correct |
213 ms |
186024 KB |
Output is correct |
70 |
Correct |
201 ms |
185936 KB |
Output is correct |
71 |
Correct |
208 ms |
186016 KB |
Output is correct |
72 |
Correct |
212 ms |
186012 KB |
Output is correct |
73 |
Correct |
189 ms |
186012 KB |
Output is correct |
74 |
Correct |
166 ms |
186192 KB |
Output is correct |
75 |
Correct |
196 ms |
185936 KB |
Output is correct |
76 |
Correct |
291 ms |
185944 KB |
Output is correct |
77 |
Correct |
237 ms |
186192 KB |
Output is correct |
78 |
Correct |
184 ms |
185940 KB |
Output is correct |
79 |
Correct |
190 ms |
185936 KB |
Output is correct |
80 |
Correct |
239 ms |
186016 KB |
Output is correct |
81 |
Correct |
183 ms |
186016 KB |
Output is correct |
82 |
Correct |
193 ms |
185944 KB |
Output is correct |
83 |
Correct |
227 ms |
186012 KB |
Output is correct |
84 |
Correct |
204 ms |
185940 KB |
Output is correct |
85 |
Correct |
206 ms |
185936 KB |
Output is correct |
86 |
Correct |
217 ms |
185864 KB |
Output is correct |
87 |
Correct |
199 ms |
186012 KB |
Output is correct |
88 |
Correct |
247 ms |
186012 KB |
Output is correct |
89 |
Correct |
243 ms |
186016 KB |
Output is correct |
90 |
Correct |
208 ms |
185920 KB |
Output is correct |
91 |
Correct |
246 ms |
185936 KB |
Output is correct |
92 |
Correct |
229 ms |
185936 KB |
Output is correct |
93 |
Correct |
238 ms |
186016 KB |
Output is correct |