#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll inf = 1e18;
const int maxn = 205;
ll n,l;
ll x[maxn], t[maxn];
ll dp[maxn][maxn][2][maxn]; // left end, right end, which end?, taken
// 0, 1,2,...,n
// n+1
ll f(int l, int r, int p, int taken) {
if (l<0 || l>n+1) return inf;
if (r<0 || r>n+1) return inf;
if (p<0) return inf;
ll &res = dp[l][r][p][taken];
if (~res) return res;
res = inf;
// don't take
if (p==0 && l>0) {
res = min(res, f(l-1,r,0,taken)+(x[l]-x[l-1]));
res = min(res, f(l-1,r,1,taken)+(x[n+1]-x[r])+x[l]);
}
if (p==1 && r<n+1) {
res = min(res, f(l,r+1,1,taken)+(x[r+1]-x[r]));
res = min(res, f(l,r+1,0,taken)+x[l]+(x[n+1]-x[r]));
}
// take
if (taken>0) {
ll tmp = -1;
if (p==0 && l>0) {
tmp = f(l-1,r,0,taken-1)+(x[l]-x[l-1]);
if (tmp<=t[l]) {
res = min(res, tmp);
}
tmp = f(l-1,r,1,taken-1)+(x[n+1]-x[r])+x[l];
if (tmp<=t[l]) {
res = min(res, tmp);
}
}
if (p==1 && r<n+1) {
tmp = f(l,r+1,1,taken-1)+(x[r+1]-x[r]);
if (tmp<=t[r]) {
res = min(res, tmp);
}
tmp = f(l,r+1,0,taken-1)+(x[n+1]-x[r])+x[l];
if (tmp<=t[r]) {
res = min(res, tmp);
}
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>l;
for (int i=1; i<=n; i++) {
cin>>x[i];
}
x[0] = 0;
x[n+1] = l;
for (int i=1; i<=n; i++) {
cin>>t[i];
}
int ans = 0;
memset(dp,-1,sizeof(dp));
dp[0][n+1][0][0] = 0;
dp[0][n+1][1][0] = 0;
for (int x=0; x<n+1; x++) {
for (int taken=1; taken<=n; taken++) {
if (f(x,x+1,0,taken)<inf) ans = max(ans, taken);
if (f(x,x+1,1,taken)<inf) ans = max(ans, taken);
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
135148 KB |
Output is correct |
2 |
Correct |
69 ms |
135276 KB |
Output is correct |
3 |
Correct |
70 ms |
135292 KB |
Output is correct |
4 |
Correct |
70 ms |
135148 KB |
Output is correct |
5 |
Correct |
70 ms |
135148 KB |
Output is correct |
6 |
Correct |
71 ms |
135148 KB |
Output is correct |
7 |
Correct |
69 ms |
135148 KB |
Output is correct |
8 |
Correct |
69 ms |
135148 KB |
Output is correct |
9 |
Correct |
69 ms |
135148 KB |
Output is correct |
10 |
Correct |
71 ms |
135148 KB |
Output is correct |
11 |
Correct |
70 ms |
135296 KB |
Output is correct |
12 |
Correct |
69 ms |
135148 KB |
Output is correct |
13 |
Correct |
70 ms |
135148 KB |
Output is correct |
14 |
Correct |
71 ms |
135148 KB |
Output is correct |
15 |
Correct |
71 ms |
135148 KB |
Output is correct |
16 |
Correct |
71 ms |
135276 KB |
Output is correct |
17 |
Correct |
69 ms |
135276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
135148 KB |
Output is correct |
2 |
Correct |
69 ms |
135276 KB |
Output is correct |
3 |
Correct |
70 ms |
135292 KB |
Output is correct |
4 |
Correct |
70 ms |
135148 KB |
Output is correct |
5 |
Correct |
70 ms |
135148 KB |
Output is correct |
6 |
Correct |
71 ms |
135148 KB |
Output is correct |
7 |
Correct |
69 ms |
135148 KB |
Output is correct |
8 |
Correct |
69 ms |
135148 KB |
Output is correct |
9 |
Correct |
69 ms |
135148 KB |
Output is correct |
10 |
Correct |
71 ms |
135148 KB |
Output is correct |
11 |
Correct |
70 ms |
135296 KB |
Output is correct |
12 |
Correct |
69 ms |
135148 KB |
Output is correct |
13 |
Correct |
70 ms |
135148 KB |
Output is correct |
14 |
Correct |
71 ms |
135148 KB |
Output is correct |
15 |
Correct |
71 ms |
135148 KB |
Output is correct |
16 |
Correct |
71 ms |
135276 KB |
Output is correct |
17 |
Correct |
69 ms |
135276 KB |
Output is correct |
18 |
Correct |
69 ms |
135148 KB |
Output is correct |
19 |
Correct |
68 ms |
135148 KB |
Output is correct |
20 |
Correct |
72 ms |
135148 KB |
Output is correct |
21 |
Correct |
70 ms |
135148 KB |
Output is correct |
22 |
Correct |
71 ms |
135148 KB |
Output is correct |
23 |
Correct |
68 ms |
135148 KB |
Output is correct |
24 |
Correct |
70 ms |
135404 KB |
Output is correct |
25 |
Correct |
69 ms |
135148 KB |
Output is correct |
26 |
Correct |
70 ms |
135276 KB |
Output is correct |
27 |
Correct |
71 ms |
135148 KB |
Output is correct |
28 |
Correct |
69 ms |
135148 KB |
Output is correct |
29 |
Correct |
71 ms |
135148 KB |
Output is correct |
30 |
Correct |
70 ms |
135148 KB |
Output is correct |
31 |
Correct |
69 ms |
135276 KB |
Output is correct |
32 |
Correct |
69 ms |
135148 KB |
Output is correct |
33 |
Correct |
70 ms |
135148 KB |
Output is correct |
34 |
Correct |
71 ms |
135148 KB |
Output is correct |
35 |
Correct |
68 ms |
135148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
135148 KB |
Output is correct |
2 |
Correct |
69 ms |
135276 KB |
Output is correct |
3 |
Correct |
70 ms |
135292 KB |
Output is correct |
4 |
Correct |
70 ms |
135148 KB |
Output is correct |
5 |
Correct |
70 ms |
135148 KB |
Output is correct |
6 |
Correct |
71 ms |
135148 KB |
Output is correct |
7 |
Correct |
69 ms |
135148 KB |
Output is correct |
8 |
Correct |
69 ms |
135148 KB |
Output is correct |
9 |
Correct |
69 ms |
135148 KB |
Output is correct |
10 |
Correct |
71 ms |
135148 KB |
Output is correct |
11 |
Correct |
70 ms |
135296 KB |
Output is correct |
12 |
Correct |
69 ms |
135148 KB |
Output is correct |
13 |
Correct |
70 ms |
135148 KB |
Output is correct |
14 |
Correct |
71 ms |
135148 KB |
Output is correct |
15 |
Correct |
71 ms |
135148 KB |
Output is correct |
16 |
Correct |
71 ms |
135276 KB |
Output is correct |
17 |
Correct |
69 ms |
135276 KB |
Output is correct |
18 |
Correct |
275 ms |
135276 KB |
Output is correct |
19 |
Correct |
167 ms |
135276 KB |
Output is correct |
20 |
Correct |
106 ms |
135276 KB |
Output is correct |
21 |
Correct |
165 ms |
135276 KB |
Output is correct |
22 |
Correct |
200 ms |
135276 KB |
Output is correct |
23 |
Correct |
98 ms |
135276 KB |
Output is correct |
24 |
Correct |
88 ms |
135276 KB |
Output is correct |
25 |
Correct |
100 ms |
135276 KB |
Output is correct |
26 |
Correct |
75 ms |
135148 KB |
Output is correct |
27 |
Correct |
102 ms |
135276 KB |
Output is correct |
28 |
Correct |
93 ms |
135276 KB |
Output is correct |
29 |
Correct |
101 ms |
135276 KB |
Output is correct |
30 |
Correct |
92 ms |
135276 KB |
Output is correct |
31 |
Correct |
96 ms |
135276 KB |
Output is correct |
32 |
Correct |
78 ms |
135148 KB |
Output is correct |
33 |
Correct |
99 ms |
135276 KB |
Output is correct |
34 |
Correct |
77 ms |
135148 KB |
Output is correct |
35 |
Correct |
98 ms |
135276 KB |
Output is correct |
36 |
Correct |
80 ms |
135148 KB |
Output is correct |
37 |
Correct |
100 ms |
135276 KB |
Output is correct |
38 |
Correct |
83 ms |
135148 KB |
Output is correct |
39 |
Correct |
100 ms |
135276 KB |
Output is correct |
40 |
Correct |
84 ms |
135148 KB |
Output is correct |
41 |
Correct |
357 ms |
135284 KB |
Output is correct |
42 |
Correct |
223 ms |
135276 KB |
Output is correct |
43 |
Correct |
350 ms |
135404 KB |
Output is correct |
44 |
Correct |
221 ms |
135284 KB |
Output is correct |
45 |
Correct |
359 ms |
135276 KB |
Output is correct |
46 |
Correct |
229 ms |
135276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
135148 KB |
Output is correct |
2 |
Correct |
69 ms |
135276 KB |
Output is correct |
3 |
Correct |
70 ms |
135292 KB |
Output is correct |
4 |
Correct |
70 ms |
135148 KB |
Output is correct |
5 |
Correct |
70 ms |
135148 KB |
Output is correct |
6 |
Correct |
71 ms |
135148 KB |
Output is correct |
7 |
Correct |
69 ms |
135148 KB |
Output is correct |
8 |
Correct |
69 ms |
135148 KB |
Output is correct |
9 |
Correct |
69 ms |
135148 KB |
Output is correct |
10 |
Correct |
71 ms |
135148 KB |
Output is correct |
11 |
Correct |
70 ms |
135296 KB |
Output is correct |
12 |
Correct |
69 ms |
135148 KB |
Output is correct |
13 |
Correct |
70 ms |
135148 KB |
Output is correct |
14 |
Correct |
71 ms |
135148 KB |
Output is correct |
15 |
Correct |
71 ms |
135148 KB |
Output is correct |
16 |
Correct |
71 ms |
135276 KB |
Output is correct |
17 |
Correct |
69 ms |
135276 KB |
Output is correct |
18 |
Correct |
69 ms |
135148 KB |
Output is correct |
19 |
Correct |
68 ms |
135148 KB |
Output is correct |
20 |
Correct |
72 ms |
135148 KB |
Output is correct |
21 |
Correct |
70 ms |
135148 KB |
Output is correct |
22 |
Correct |
71 ms |
135148 KB |
Output is correct |
23 |
Correct |
68 ms |
135148 KB |
Output is correct |
24 |
Correct |
70 ms |
135404 KB |
Output is correct |
25 |
Correct |
69 ms |
135148 KB |
Output is correct |
26 |
Correct |
70 ms |
135276 KB |
Output is correct |
27 |
Correct |
71 ms |
135148 KB |
Output is correct |
28 |
Correct |
69 ms |
135148 KB |
Output is correct |
29 |
Correct |
71 ms |
135148 KB |
Output is correct |
30 |
Correct |
70 ms |
135148 KB |
Output is correct |
31 |
Correct |
69 ms |
135276 KB |
Output is correct |
32 |
Correct |
69 ms |
135148 KB |
Output is correct |
33 |
Correct |
70 ms |
135148 KB |
Output is correct |
34 |
Correct |
71 ms |
135148 KB |
Output is correct |
35 |
Correct |
68 ms |
135148 KB |
Output is correct |
36 |
Correct |
275 ms |
135276 KB |
Output is correct |
37 |
Correct |
167 ms |
135276 KB |
Output is correct |
38 |
Correct |
106 ms |
135276 KB |
Output is correct |
39 |
Correct |
165 ms |
135276 KB |
Output is correct |
40 |
Correct |
200 ms |
135276 KB |
Output is correct |
41 |
Correct |
98 ms |
135276 KB |
Output is correct |
42 |
Correct |
88 ms |
135276 KB |
Output is correct |
43 |
Correct |
100 ms |
135276 KB |
Output is correct |
44 |
Correct |
75 ms |
135148 KB |
Output is correct |
45 |
Correct |
102 ms |
135276 KB |
Output is correct |
46 |
Correct |
93 ms |
135276 KB |
Output is correct |
47 |
Correct |
101 ms |
135276 KB |
Output is correct |
48 |
Correct |
92 ms |
135276 KB |
Output is correct |
49 |
Correct |
96 ms |
135276 KB |
Output is correct |
50 |
Correct |
78 ms |
135148 KB |
Output is correct |
51 |
Correct |
99 ms |
135276 KB |
Output is correct |
52 |
Correct |
77 ms |
135148 KB |
Output is correct |
53 |
Correct |
98 ms |
135276 KB |
Output is correct |
54 |
Correct |
80 ms |
135148 KB |
Output is correct |
55 |
Correct |
100 ms |
135276 KB |
Output is correct |
56 |
Correct |
83 ms |
135148 KB |
Output is correct |
57 |
Correct |
100 ms |
135276 KB |
Output is correct |
58 |
Correct |
84 ms |
135148 KB |
Output is correct |
59 |
Correct |
357 ms |
135284 KB |
Output is correct |
60 |
Correct |
223 ms |
135276 KB |
Output is correct |
61 |
Correct |
350 ms |
135404 KB |
Output is correct |
62 |
Correct |
221 ms |
135284 KB |
Output is correct |
63 |
Correct |
359 ms |
135276 KB |
Output is correct |
64 |
Correct |
229 ms |
135276 KB |
Output is correct |
65 |
Correct |
315 ms |
135276 KB |
Output is correct |
66 |
Correct |
294 ms |
135404 KB |
Output is correct |
67 |
Correct |
268 ms |
135276 KB |
Output is correct |
68 |
Correct |
244 ms |
135276 KB |
Output is correct |
69 |
Correct |
310 ms |
135404 KB |
Output is correct |
70 |
Correct |
300 ms |
135276 KB |
Output is correct |
71 |
Correct |
298 ms |
135276 KB |
Output is correct |
72 |
Correct |
303 ms |
135276 KB |
Output is correct |
73 |
Correct |
275 ms |
135276 KB |
Output is correct |
74 |
Correct |
259 ms |
135276 KB |
Output is correct |
75 |
Correct |
283 ms |
135276 KB |
Output is correct |
76 |
Correct |
363 ms |
135308 KB |
Output is correct |
77 |
Correct |
342 ms |
135288 KB |
Output is correct |
78 |
Correct |
255 ms |
135220 KB |
Output is correct |
79 |
Correct |
328 ms |
135288 KB |
Output is correct |
80 |
Correct |
340 ms |
135404 KB |
Output is correct |
81 |
Correct |
267 ms |
135276 KB |
Output is correct |
82 |
Correct |
276 ms |
135368 KB |
Output is correct |
83 |
Correct |
347 ms |
135288 KB |
Output is correct |
84 |
Correct |
291 ms |
135412 KB |
Output is correct |
85 |
Correct |
322 ms |
135404 KB |
Output is correct |
86 |
Correct |
314 ms |
135404 KB |
Output is correct |
87 |
Correct |
288 ms |
135404 KB |
Output is correct |
88 |
Correct |
358 ms |
135276 KB |
Output is correct |
89 |
Correct |
360 ms |
135276 KB |
Output is correct |
90 |
Correct |
288 ms |
135276 KB |
Output is correct |
91 |
Correct |
361 ms |
135384 KB |
Output is correct |
92 |
Correct |
355 ms |
135276 KB |
Output is correct |
93 |
Correct |
344 ms |
135276 KB |
Output is correct |