#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;
const int N = 205;
const long long oo = 1e18;
long long dp[N][N][N][2];
int costl[N];
int costr[N];
int a[N];
int t[N];
int n,L;
template <typename T>
bool mini(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> L;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> t[i];
a[++n] = L;
for (int i = 0; i < n; i++)
costr[i] = a[i + 1] - a[i];
for (int i = 1; i <= n; i++)
costl[i % n] = a[i] - a[i - 1];
// for (int i = 0; i < n; i++)
// cerr << costr[i] << " \n"[i == n - 1];
// for (int i = 0; i < n; i++)
// cerr << costl[i] << " \n"[i == n - 1];
for (int l = 0; l < n; l++)
for (int r = 0; r < n; r++)
for (int cnt = 0; cnt < n; cnt++)
for (int side = 0; side < 2; side++)
dp[l][r][cnt][side] = oo;
dp[0][0][0][0] = dp[0][0][0][1] = 0;
for (int l = 0, cntl = n; cntl > 0; l = (l + n - 1) % n, cntl--)
for (int r = 0, cntr = cntl - 1; cntr > 0; r = (r + 1) % n, cntr--)
for (int cnt = 0; cnt < n; cnt++)
for (int side = 0; side < 2; side++) {
long long cur = dp[l][r][cnt][side];
if (cur == oo)
continue;
int add = a[r] + (L - a[l]) % L;
long long cost;
cost = 1LL * (side == 0) * add + costr[r];
int nxtr = (r + 1) % n;
mini(dp[l][nxtr][cnt + (cur + cost <= t[nxtr])][1], cur + cost);
cost = 1LL * (side == 1) * add + costl[l];
int nxtl = (l + n - 1) % n;
mini(dp[nxtl][r][cnt + (cur + cost <= t[nxtl])][0], cur + cost);
}
int ans = 0;
for (int cnt = 0; cnt < n; cnt++)
for (int l = 0; l < n; l++)
for (int r = 0; r < n; r++)
for (int side = 0; side < 2; side++)
if (dp[l][r][cnt][side] < oo)
ans = cnt;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
968 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
844 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
968 KB |
Output is correct |
26 |
Correct |
1 ms |
972 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
127 ms |
104932 KB |
Output is correct |
19 |
Correct |
67 ms |
63692 KB |
Output is correct |
20 |
Correct |
29 ms |
34020 KB |
Output is correct |
21 |
Correct |
62 ms |
60020 KB |
Output is correct |
22 |
Correct |
89 ms |
77952 KB |
Output is correct |
23 |
Correct |
26 ms |
28876 KB |
Output is correct |
24 |
Correct |
17 ms |
22628 KB |
Output is correct |
25 |
Correct |
28 ms |
28288 KB |
Output is correct |
26 |
Correct |
7 ms |
10828 KB |
Output is correct |
27 |
Correct |
29 ms |
29512 KB |
Output is correct |
28 |
Correct |
16 ms |
21092 KB |
Output is correct |
29 |
Correct |
27 ms |
30152 KB |
Output is correct |
30 |
Correct |
18 ms |
23628 KB |
Output is correct |
31 |
Correct |
24 ms |
28352 KB |
Output is correct |
32 |
Correct |
11 ms |
14916 KB |
Output is correct |
33 |
Correct |
25 ms |
28236 KB |
Output is correct |
34 |
Correct |
7 ms |
10060 KB |
Output is correct |
35 |
Correct |
22 ms |
27724 KB |
Output is correct |
36 |
Correct |
11 ms |
13240 KB |
Output is correct |
37 |
Correct |
25 ms |
29516 KB |
Output is correct |
38 |
Correct |
12 ms |
16232 KB |
Output is correct |
39 |
Correct |
24 ms |
30796 KB |
Output is correct |
40 |
Correct |
14 ms |
18108 KB |
Output is correct |
41 |
Correct |
179 ms |
129472 KB |
Output is correct |
42 |
Correct |
87 ms |
87152 KB |
Output is correct |
43 |
Correct |
190 ms |
129476 KB |
Output is correct |
44 |
Correct |
81 ms |
86212 KB |
Output is correct |
45 |
Correct |
177 ms |
129424 KB |
Output is correct |
46 |
Correct |
82 ms |
87112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
968 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
844 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
968 KB |
Output is correct |
26 |
Correct |
1 ms |
972 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
36 |
Correct |
127 ms |
104932 KB |
Output is correct |
37 |
Correct |
67 ms |
63692 KB |
Output is correct |
38 |
Correct |
29 ms |
34020 KB |
Output is correct |
39 |
Correct |
62 ms |
60020 KB |
Output is correct |
40 |
Correct |
89 ms |
77952 KB |
Output is correct |
41 |
Correct |
26 ms |
28876 KB |
Output is correct |
42 |
Correct |
17 ms |
22628 KB |
Output is correct |
43 |
Correct |
28 ms |
28288 KB |
Output is correct |
44 |
Correct |
7 ms |
10828 KB |
Output is correct |
45 |
Correct |
29 ms |
29512 KB |
Output is correct |
46 |
Correct |
16 ms |
21092 KB |
Output is correct |
47 |
Correct |
27 ms |
30152 KB |
Output is correct |
48 |
Correct |
18 ms |
23628 KB |
Output is correct |
49 |
Correct |
24 ms |
28352 KB |
Output is correct |
50 |
Correct |
11 ms |
14916 KB |
Output is correct |
51 |
Correct |
25 ms |
28236 KB |
Output is correct |
52 |
Correct |
7 ms |
10060 KB |
Output is correct |
53 |
Correct |
22 ms |
27724 KB |
Output is correct |
54 |
Correct |
11 ms |
13240 KB |
Output is correct |
55 |
Correct |
25 ms |
29516 KB |
Output is correct |
56 |
Correct |
12 ms |
16232 KB |
Output is correct |
57 |
Correct |
24 ms |
30796 KB |
Output is correct |
58 |
Correct |
14 ms |
18108 KB |
Output is correct |
59 |
Correct |
179 ms |
129472 KB |
Output is correct |
60 |
Correct |
87 ms |
87152 KB |
Output is correct |
61 |
Correct |
190 ms |
129476 KB |
Output is correct |
62 |
Correct |
81 ms |
86212 KB |
Output is correct |
63 |
Correct |
177 ms |
129424 KB |
Output is correct |
64 |
Correct |
82 ms |
87112 KB |
Output is correct |
65 |
Correct |
154 ms |
116908 KB |
Output is correct |
66 |
Correct |
136 ms |
107332 KB |
Output is correct |
67 |
Correct |
125 ms |
102588 KB |
Output is correct |
68 |
Correct |
120 ms |
94712 KB |
Output is correct |
69 |
Correct |
153 ms |
115592 KB |
Output is correct |
70 |
Correct |
148 ms |
110832 KB |
Output is correct |
71 |
Correct |
158 ms |
112160 KB |
Output is correct |
72 |
Correct |
146 ms |
113144 KB |
Output is correct |
73 |
Correct |
118 ms |
104904 KB |
Output is correct |
74 |
Correct |
127 ms |
98120 KB |
Output is correct |
75 |
Correct |
133 ms |
108412 KB |
Output is correct |
76 |
Correct |
169 ms |
124360 KB |
Output is correct |
77 |
Correct |
159 ms |
124352 KB |
Output is correct |
78 |
Correct |
121 ms |
95940 KB |
Output is correct |
79 |
Correct |
131 ms |
99224 KB |
Output is correct |
80 |
Correct |
180 ms |
121836 KB |
Output is correct |
81 |
Correct |
119 ms |
100368 KB |
Output is correct |
82 |
Correct |
122 ms |
106016 KB |
Output is correct |
83 |
Correct |
175 ms |
129476 KB |
Output is correct |
84 |
Correct |
132 ms |
110852 KB |
Output is correct |
85 |
Correct |
145 ms |
120532 KB |
Output is correct |
86 |
Correct |
139 ms |
118084 KB |
Output is correct |
87 |
Correct |
139 ms |
108512 KB |
Output is correct |
88 |
Correct |
190 ms |
130704 KB |
Output is correct |
89 |
Correct |
179 ms |
130636 KB |
Output is correct |
90 |
Correct |
115 ms |
109820 KB |
Output is correct |
91 |
Correct |
204 ms |
130760 KB |
Output is correct |
92 |
Correct |
178 ms |
130756 KB |
Output is correct |
93 |
Correct |
134 ms |
128160 KB |
Output is correct |