/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 205;
int n, L, x[N], t[N], ans;
int dp[N][N][N][2];
int sf(int x)
{
return n - x + 1;
}
int main()
{
cin >> n >> L;
for (int i = 1; i <= n; i++)
cin >> x[i];
for (int i = 1; i <= n; i++)
cin >> t[i];
for (int s = 0; s <= n; s++)
for (int p = 0; p <= n; p++)
for (int i = 0; i <= n; i++)
dp[p][s][i][0] = dp[p][s][i][1] = mod;
dp[0][0][0][1] = dp[0][0][0][0] = 0;
x[n + 1] = L;
for (int c = 0; c < n; c++)
for (int p = 0; p <= c; p++)
for (int C = 0; C < n; C++)
{
int s = c - p;
int T;
//left
T = dp[p][s][C][0];
dp[p + 1][s][C + (T + x[p + 1] - x[p] <= t[p + 1])][0] = min(dp[p + 1][s][C + (T + x[p + 1] - x[p] <= t[p + 1])][0],T + x[p + 1] - x[p]);
dp[p][s + 1][C + (T + x[p] + L - x[sf(s + 1)] <= t[sf(s + 1)])][1] = min(dp[p][s + 1][C + (T + x[p] + L - x[sf(s + 1)] <= t[sf(s + 1)])][1],T + x[p] + L - x[sf(s + 1)]);
//right
T = dp[p][s][C][1];
dp[p][s + 1][C + (T + x[sf(s)] - x[sf(s + 1)] <= t[sf(s + 1)])][1] = min(dp[p][s + 1][C + (T + x[sf(s)] - x[sf(s + 1)] <= t[sf(s + 1)])][1], T + x[sf(s)] - x[sf(s + 1)]);
dp[p + 1][s][C + (T + x[p + 1] + L - x[sf(s)] <= t[p + 1])][0] = min(dp[p + 1][s][C + (T + x[p + 1] + L - x[sf(s)] <= t[p + 1])][0], T + x[p + 1] + L - x[sf(s)]);
}
for (int c = 0; c <= n; c++)
for (int p = 0; p <= n; p++)
for (int s = 0; s <= n; s++)
for (int d = 0; d <= 1; d++)
if (dp[p][s][c][d] != mod)
ans = c;
cout << ans << endl;
return 0;
}
/*
5
1 2 3 4 5
5 4 3 2 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 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 |
632 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
380 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 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 |
632 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
380 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
760 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
21 |
Correct |
5 ms |
760 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
760 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
760 KB |
Output is correct |
26 |
Correct |
5 ms |
760 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
504 KB |
Output is correct |
29 |
Correct |
5 ms |
760 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
5 ms |
760 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 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 |
632 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
380 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
122 ms |
52984 KB |
Output is correct |
19 |
Correct |
63 ms |
32248 KB |
Output is correct |
20 |
Correct |
30 ms |
17400 KB |
Output is correct |
21 |
Correct |
60 ms |
30588 KB |
Output is correct |
22 |
Correct |
82 ms |
39416 KB |
Output is correct |
23 |
Correct |
25 ms |
14840 KB |
Output is correct |
24 |
Correct |
19 ms |
11640 KB |
Output is correct |
25 |
Correct |
25 ms |
14460 KB |
Output is correct |
26 |
Correct |
10 ms |
5752 KB |
Output is correct |
27 |
Correct |
26 ms |
15096 KB |
Output is correct |
28 |
Correct |
17 ms |
10872 KB |
Output is correct |
29 |
Correct |
27 ms |
15480 KB |
Output is correct |
30 |
Correct |
20 ms |
12152 KB |
Output is correct |
31 |
Correct |
25 ms |
14584 KB |
Output is correct |
32 |
Correct |
13 ms |
7800 KB |
Output is correct |
33 |
Correct |
25 ms |
14456 KB |
Output is correct |
34 |
Correct |
9 ms |
5368 KB |
Output is correct |
35 |
Correct |
24 ms |
14200 KB |
Output is correct |
36 |
Correct |
12 ms |
6904 KB |
Output is correct |
37 |
Correct |
26 ms |
15096 KB |
Output is correct |
38 |
Correct |
16 ms |
8440 KB |
Output is correct |
39 |
Correct |
27 ms |
15736 KB |
Output is correct |
40 |
Correct |
16 ms |
9336 KB |
Output is correct |
41 |
Correct |
166 ms |
65272 KB |
Output is correct |
42 |
Correct |
96 ms |
44152 KB |
Output is correct |
43 |
Correct |
167 ms |
65272 KB |
Output is correct |
44 |
Correct |
96 ms |
43512 KB |
Output is correct |
45 |
Correct |
166 ms |
65352 KB |
Output is correct |
46 |
Correct |
97 ms |
44156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 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 |
632 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
380 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
760 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
21 |
Correct |
5 ms |
760 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
760 KB |
Output is correct |
24 |
Correct |
5 ms |
632 KB |
Output is correct |
25 |
Correct |
5 ms |
760 KB |
Output is correct |
26 |
Correct |
5 ms |
760 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
504 KB |
Output is correct |
29 |
Correct |
5 ms |
760 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
5 ms |
760 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
36 |
Correct |
122 ms |
52984 KB |
Output is correct |
37 |
Correct |
63 ms |
32248 KB |
Output is correct |
38 |
Correct |
30 ms |
17400 KB |
Output is correct |
39 |
Correct |
60 ms |
30588 KB |
Output is correct |
40 |
Correct |
82 ms |
39416 KB |
Output is correct |
41 |
Correct |
25 ms |
14840 KB |
Output is correct |
42 |
Correct |
19 ms |
11640 KB |
Output is correct |
43 |
Correct |
25 ms |
14460 KB |
Output is correct |
44 |
Correct |
10 ms |
5752 KB |
Output is correct |
45 |
Correct |
26 ms |
15096 KB |
Output is correct |
46 |
Correct |
17 ms |
10872 KB |
Output is correct |
47 |
Correct |
27 ms |
15480 KB |
Output is correct |
48 |
Correct |
20 ms |
12152 KB |
Output is correct |
49 |
Correct |
25 ms |
14584 KB |
Output is correct |
50 |
Correct |
13 ms |
7800 KB |
Output is correct |
51 |
Correct |
25 ms |
14456 KB |
Output is correct |
52 |
Correct |
9 ms |
5368 KB |
Output is correct |
53 |
Correct |
24 ms |
14200 KB |
Output is correct |
54 |
Correct |
12 ms |
6904 KB |
Output is correct |
55 |
Correct |
26 ms |
15096 KB |
Output is correct |
56 |
Correct |
16 ms |
8440 KB |
Output is correct |
57 |
Correct |
27 ms |
15736 KB |
Output is correct |
58 |
Correct |
16 ms |
9336 KB |
Output is correct |
59 |
Correct |
166 ms |
65272 KB |
Output is correct |
60 |
Correct |
96 ms |
44152 KB |
Output is correct |
61 |
Correct |
167 ms |
65272 KB |
Output is correct |
62 |
Correct |
96 ms |
43512 KB |
Output is correct |
63 |
Correct |
166 ms |
65352 KB |
Output is correct |
64 |
Correct |
97 ms |
44156 KB |
Output is correct |
65 |
Correct |
143 ms |
59000 KB |
Output is correct |
66 |
Correct |
130 ms |
54240 KB |
Output is correct |
67 |
Correct |
121 ms |
51832 KB |
Output is correct |
68 |
Correct |
105 ms |
47864 KB |
Output is correct |
69 |
Correct |
140 ms |
58360 KB |
Output is correct |
70 |
Correct |
137 ms |
55928 KB |
Output is correct |
71 |
Correct |
135 ms |
56568 KB |
Output is correct |
72 |
Correct |
137 ms |
57212 KB |
Output is correct |
73 |
Correct |
123 ms |
52984 KB |
Output is correct |
74 |
Correct |
119 ms |
49528 KB |
Output is correct |
75 |
Correct |
130 ms |
54776 KB |
Output is correct |
76 |
Correct |
155 ms |
62716 KB |
Output is correct |
77 |
Correct |
154 ms |
62712 KB |
Output is correct |
78 |
Correct |
110 ms |
48376 KB |
Output is correct |
79 |
Correct |
114 ms |
50168 KB |
Output is correct |
80 |
Correct |
152 ms |
61432 KB |
Output is correct |
81 |
Correct |
115 ms |
50680 KB |
Output is correct |
82 |
Correct |
125 ms |
53624 KB |
Output is correct |
83 |
Correct |
170 ms |
65360 KB |
Output is correct |
84 |
Correct |
133 ms |
55928 KB |
Output is correct |
85 |
Correct |
152 ms |
60792 KB |
Output is correct |
86 |
Correct |
147 ms |
59640 KB |
Output is correct |
87 |
Correct |
127 ms |
54776 KB |
Output is correct |
88 |
Correct |
170 ms |
65912 KB |
Output is correct |
89 |
Correct |
169 ms |
65912 KB |
Output is correct |
90 |
Correct |
133 ms |
55420 KB |
Output is correct |
91 |
Correct |
167 ms |
65912 KB |
Output is correct |
92 |
Correct |
169 ms |
65912 KB |
Output is correct |
93 |
Correct |
168 ms |
64760 KB |
Output is correct |