#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 205;
int x[N];
int t[N];
ll f[N][N][N][2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int L; cin >> L;
for(int i = 1 ; i <= n ; ++i) cin >> x[i];
for(int i = 1 ; i <= n ; ++i) cin >> t[i];
for(int i = 1 ; i <= n ; ++i)
f[0][0][i][0] = 2e18,
f[0][0][i][1] = 2e18;
x[n + 1] = L;
for(int i = 0 ; i <= n ; ++i)
for(int j = 0 ; j <= n ; ++j) {
if (i < 1 && j < 1) continue;
if (i + j > n) break;
for(int k = 0 ; k <= n ; ++k) {
ll& res1 = f[i][j][k][0]; res1 = 2e18;
ll& res2 = f[i][j][k][1]; res2 = 2e18;
if (i)
res1 = min(res1,f[i - 1][j][k][0] + x[n - i + 2] - x[n - i + 1]),
res1 = min(res1,f[i - 1][j][k][1] + x[j] + L - x[n - i + 1]);
if (j)
res2 = min(res2,f[i][j - 1][k][0] + x[j] + L - x[n - i + 1]),
res2 = min(res2,f[i][j - 1][k][1] + x[j] - x[j - 1]);
if (k == 0) continue;
ll nxt;
if (i) {
if ((nxt = f[i - 1][j][k - 1][0] + x[n - i + 2] - x[n - i + 1]) <= t[n - i + 1]) res1 = min(res1,nxt);
if ((nxt = f[i - 1][j][k - 1][1] + x[j] + L - x[n - i + 1]) <= t[n - i + 1]) res1 = min(res1,nxt);
}
if (j) {
if ((nxt = f[i][j - 1][k - 1][0] + x[j] + L - x[n - i + 1]) <= t[j]) res2 = min(res2,nxt);
if ((nxt = f[i][j - 1][k - 1][1] + x[j] - x[j - 1]) <= t[j]) res2 = min(res2,nxt);
}
}
}
int ans = 0;
for(int i = 0 ; i <= n ; ++i)
for(int k = 0 ; k <= n ; ++k) {
if (f[i][n - i][k][0] < 2e18) ans = max(ans,k);
if (f[i][n - i][k][1] < 2e18) ans = max(ans,k);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
564 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
768 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
768 KB |
Output is correct |
24 |
Correct |
1 ms |
768 KB |
Output is correct |
25 |
Correct |
1 ms |
768 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
0 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
768 KB |
Output is correct |
30 |
Correct |
1 ms |
768 KB |
Output is correct |
31 |
Correct |
1 ms |
768 KB |
Output is correct |
32 |
Correct |
1 ms |
768 KB |
Output is correct |
33 |
Correct |
1 ms |
768 KB |
Output is correct |
34 |
Correct |
1 ms |
768 KB |
Output is correct |
35 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
51 ms |
53368 KB |
Output is correct |
19 |
Correct |
37 ms |
32508 KB |
Output is correct |
20 |
Correct |
13 ms |
17536 KB |
Output is correct |
21 |
Correct |
24 ms |
30712 KB |
Output is correct |
22 |
Correct |
35 ms |
39800 KB |
Output is correct |
23 |
Correct |
12 ms |
14976 KB |
Output is correct |
24 |
Correct |
8 ms |
11776 KB |
Output is correct |
25 |
Correct |
10 ms |
14720 KB |
Output is correct |
26 |
Correct |
4 ms |
5760 KB |
Output is correct |
27 |
Correct |
11 ms |
15232 KB |
Output is correct |
28 |
Correct |
8 ms |
11008 KB |
Output is correct |
29 |
Correct |
11 ms |
15616 KB |
Output is correct |
30 |
Correct |
8 ms |
12288 KB |
Output is correct |
31 |
Correct |
10 ms |
14720 KB |
Output is correct |
32 |
Correct |
5 ms |
7808 KB |
Output is correct |
33 |
Correct |
10 ms |
14720 KB |
Output is correct |
34 |
Correct |
3 ms |
5376 KB |
Output is correct |
35 |
Correct |
10 ms |
14336 KB |
Output is correct |
36 |
Correct |
4 ms |
7040 KB |
Output is correct |
37 |
Correct |
16 ms |
15232 KB |
Output is correct |
38 |
Correct |
6 ms |
8576 KB |
Output is correct |
39 |
Correct |
11 ms |
15884 KB |
Output is correct |
40 |
Correct |
7 ms |
9472 KB |
Output is correct |
41 |
Correct |
67 ms |
65784 KB |
Output is correct |
42 |
Correct |
50 ms |
44408 KB |
Output is correct |
43 |
Correct |
63 ms |
65784 KB |
Output is correct |
44 |
Correct |
37 ms |
43896 KB |
Output is correct |
45 |
Correct |
63 ms |
65784 KB |
Output is correct |
46 |
Correct |
40 ms |
44408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
564 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
768 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
768 KB |
Output is correct |
24 |
Correct |
1 ms |
768 KB |
Output is correct |
25 |
Correct |
1 ms |
768 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
0 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
768 KB |
Output is correct |
30 |
Correct |
1 ms |
768 KB |
Output is correct |
31 |
Correct |
1 ms |
768 KB |
Output is correct |
32 |
Correct |
1 ms |
768 KB |
Output is correct |
33 |
Correct |
1 ms |
768 KB |
Output is correct |
34 |
Correct |
1 ms |
768 KB |
Output is correct |
35 |
Correct |
1 ms |
768 KB |
Output is correct |
36 |
Correct |
51 ms |
53368 KB |
Output is correct |
37 |
Correct |
37 ms |
32508 KB |
Output is correct |
38 |
Correct |
13 ms |
17536 KB |
Output is correct |
39 |
Correct |
24 ms |
30712 KB |
Output is correct |
40 |
Correct |
35 ms |
39800 KB |
Output is correct |
41 |
Correct |
12 ms |
14976 KB |
Output is correct |
42 |
Correct |
8 ms |
11776 KB |
Output is correct |
43 |
Correct |
10 ms |
14720 KB |
Output is correct |
44 |
Correct |
4 ms |
5760 KB |
Output is correct |
45 |
Correct |
11 ms |
15232 KB |
Output is correct |
46 |
Correct |
8 ms |
11008 KB |
Output is correct |
47 |
Correct |
11 ms |
15616 KB |
Output is correct |
48 |
Correct |
8 ms |
12288 KB |
Output is correct |
49 |
Correct |
10 ms |
14720 KB |
Output is correct |
50 |
Correct |
5 ms |
7808 KB |
Output is correct |
51 |
Correct |
10 ms |
14720 KB |
Output is correct |
52 |
Correct |
3 ms |
5376 KB |
Output is correct |
53 |
Correct |
10 ms |
14336 KB |
Output is correct |
54 |
Correct |
4 ms |
7040 KB |
Output is correct |
55 |
Correct |
16 ms |
15232 KB |
Output is correct |
56 |
Correct |
6 ms |
8576 KB |
Output is correct |
57 |
Correct |
11 ms |
15884 KB |
Output is correct |
58 |
Correct |
7 ms |
9472 KB |
Output is correct |
59 |
Correct |
67 ms |
65784 KB |
Output is correct |
60 |
Correct |
50 ms |
44408 KB |
Output is correct |
61 |
Correct |
63 ms |
65784 KB |
Output is correct |
62 |
Correct |
37 ms |
43896 KB |
Output is correct |
63 |
Correct |
63 ms |
65784 KB |
Output is correct |
64 |
Correct |
40 ms |
44408 KB |
Output is correct |
65 |
Correct |
60 ms |
59384 KB |
Output is correct |
66 |
Correct |
51 ms |
54648 KB |
Output is correct |
67 |
Correct |
49 ms |
52216 KB |
Output is correct |
68 |
Correct |
70 ms |
48248 KB |
Output is correct |
69 |
Correct |
93 ms |
58744 KB |
Output is correct |
70 |
Correct |
65 ms |
56316 KB |
Output is correct |
71 |
Correct |
53 ms |
56952 KB |
Output is correct |
72 |
Correct |
59 ms |
57592 KB |
Output is correct |
73 |
Correct |
50 ms |
53368 KB |
Output is correct |
74 |
Correct |
50 ms |
49912 KB |
Output is correct |
75 |
Correct |
49 ms |
55168 KB |
Output is correct |
76 |
Correct |
67 ms |
63224 KB |
Output is correct |
77 |
Correct |
61 ms |
63240 KB |
Output is correct |
78 |
Correct |
47 ms |
48760 KB |
Output is correct |
79 |
Correct |
45 ms |
50552 KB |
Output is correct |
80 |
Correct |
63 ms |
61948 KB |
Output is correct |
81 |
Correct |
47 ms |
51064 KB |
Output is correct |
82 |
Correct |
51 ms |
54008 KB |
Output is correct |
83 |
Correct |
64 ms |
65788 KB |
Output is correct |
84 |
Correct |
54 ms |
56312 KB |
Output is correct |
85 |
Correct |
60 ms |
61304 KB |
Output is correct |
86 |
Correct |
59 ms |
60024 KB |
Output is correct |
87 |
Correct |
51 ms |
55164 KB |
Output is correct |
88 |
Correct |
67 ms |
66424 KB |
Output is correct |
89 |
Correct |
65 ms |
66424 KB |
Output is correct |
90 |
Correct |
53 ms |
55800 KB |
Output is correct |
91 |
Correct |
65 ms |
66424 KB |
Output is correct |
92 |
Correct |
64 ms |
66424 KB |
Output is correct |
93 |
Correct |
62 ms |
65144 KB |
Output is correct |