#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int inf = 1e9 + 1;
const ll linf = 1e18 + 1;
ll dp[201][201][201][2];
int main(){
ll n, l;
cin >> n >> l;
ll a[n + 2];
ll t[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> t[i];
}
for(int i = 0; i <= 200; i++){
for(int j = 0; j <= 200; j++){
for(int k = 0; k <= 200; k++) dp[i][j][k][0] = dp[i][j][k][1] = linf;
}
}
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
a[0] = 0;
a[n + 1] = l;
// 0 marcxniv 1 marjvniv
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i + j > n) continue;
for(int x = 0; x < n; x++){
ll nt = dp[i][j][x][0] + l - a[n - i + 1] + a[j + 1];
nt = min(nt, dp[i][j][x][1] + a[j + 1] - a[j]);
if(nt <= t[j + 1]) dp[i][j + 1][x + 1][1] = min(dp[i][j + 1][x + 1][1], nt);
else dp[i][j + 1][x][1] = min(dp[i][j + 1][x][1], nt);
nt = dp[i][j][x][0] + a[n - i + 1] - a[n - i];
nt = min(nt, dp[i][j][x][1] + l - a[n - i] + a[j]);
if(nt <= t[n - i]) dp[i + 1][j][x + 1][0] = min(dp[i + 1][j][x + 1][0], nt);
else dp[i + 1][j][x][0] = min(dp[i + 1][j][x][0], nt);
}
}
}
int ans = 0;
for(int i = 0; i <= n; i++){
for(int x = 1; x <= n; x++) {
if(dp[i][n - i][x][0] != linf) ans = max(x, ans);
if(dp[i][n - i][x][1] != linf) ans = max(x, ans);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
127308 KB |
Output is correct |
2 |
Correct |
53 ms |
127364 KB |
Output is correct |
3 |
Correct |
51 ms |
127308 KB |
Output is correct |
4 |
Correct |
54 ms |
127352 KB |
Output is correct |
5 |
Correct |
56 ms |
127296 KB |
Output is correct |
6 |
Correct |
54 ms |
127372 KB |
Output is correct |
7 |
Correct |
57 ms |
127320 KB |
Output is correct |
8 |
Correct |
53 ms |
127312 KB |
Output is correct |
9 |
Correct |
52 ms |
127328 KB |
Output is correct |
10 |
Correct |
55 ms |
127360 KB |
Output is correct |
11 |
Correct |
54 ms |
127332 KB |
Output is correct |
12 |
Correct |
57 ms |
127292 KB |
Output is correct |
13 |
Correct |
64 ms |
127308 KB |
Output is correct |
14 |
Correct |
52 ms |
127320 KB |
Output is correct |
15 |
Correct |
54 ms |
127312 KB |
Output is correct |
16 |
Correct |
62 ms |
127352 KB |
Output is correct |
17 |
Correct |
58 ms |
127388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
127308 KB |
Output is correct |
2 |
Correct |
53 ms |
127364 KB |
Output is correct |
3 |
Correct |
51 ms |
127308 KB |
Output is correct |
4 |
Correct |
54 ms |
127352 KB |
Output is correct |
5 |
Correct |
56 ms |
127296 KB |
Output is correct |
6 |
Correct |
54 ms |
127372 KB |
Output is correct |
7 |
Correct |
57 ms |
127320 KB |
Output is correct |
8 |
Correct |
53 ms |
127312 KB |
Output is correct |
9 |
Correct |
52 ms |
127328 KB |
Output is correct |
10 |
Correct |
55 ms |
127360 KB |
Output is correct |
11 |
Correct |
54 ms |
127332 KB |
Output is correct |
12 |
Correct |
57 ms |
127292 KB |
Output is correct |
13 |
Correct |
64 ms |
127308 KB |
Output is correct |
14 |
Correct |
52 ms |
127320 KB |
Output is correct |
15 |
Correct |
54 ms |
127312 KB |
Output is correct |
16 |
Correct |
62 ms |
127352 KB |
Output is correct |
17 |
Correct |
58 ms |
127388 KB |
Output is correct |
18 |
Correct |
57 ms |
127328 KB |
Output is correct |
19 |
Correct |
54 ms |
127380 KB |
Output is correct |
20 |
Correct |
63 ms |
127356 KB |
Output is correct |
21 |
Correct |
54 ms |
127288 KB |
Output is correct |
22 |
Correct |
53 ms |
127424 KB |
Output is correct |
23 |
Correct |
52 ms |
127312 KB |
Output is correct |
24 |
Correct |
57 ms |
127356 KB |
Output is correct |
25 |
Correct |
60 ms |
127360 KB |
Output is correct |
26 |
Correct |
53 ms |
127320 KB |
Output is correct |
27 |
Correct |
53 ms |
127396 KB |
Output is correct |
28 |
Correct |
56 ms |
127360 KB |
Output is correct |
29 |
Correct |
53 ms |
127348 KB |
Output is correct |
30 |
Correct |
62 ms |
127300 KB |
Output is correct |
31 |
Correct |
58 ms |
127364 KB |
Output is correct |
32 |
Correct |
56 ms |
127396 KB |
Output is correct |
33 |
Correct |
52 ms |
127364 KB |
Output is correct |
34 |
Correct |
53 ms |
127304 KB |
Output is correct |
35 |
Correct |
53 ms |
127360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
127308 KB |
Output is correct |
2 |
Correct |
53 ms |
127364 KB |
Output is correct |
3 |
Correct |
51 ms |
127308 KB |
Output is correct |
4 |
Correct |
54 ms |
127352 KB |
Output is correct |
5 |
Correct |
56 ms |
127296 KB |
Output is correct |
6 |
Correct |
54 ms |
127372 KB |
Output is correct |
7 |
Correct |
57 ms |
127320 KB |
Output is correct |
8 |
Correct |
53 ms |
127312 KB |
Output is correct |
9 |
Correct |
52 ms |
127328 KB |
Output is correct |
10 |
Correct |
55 ms |
127360 KB |
Output is correct |
11 |
Correct |
54 ms |
127332 KB |
Output is correct |
12 |
Correct |
57 ms |
127292 KB |
Output is correct |
13 |
Correct |
64 ms |
127308 KB |
Output is correct |
14 |
Correct |
52 ms |
127320 KB |
Output is correct |
15 |
Correct |
54 ms |
127312 KB |
Output is correct |
16 |
Correct |
62 ms |
127352 KB |
Output is correct |
17 |
Correct |
58 ms |
127388 KB |
Output is correct |
18 |
Correct |
82 ms |
127372 KB |
Output is correct |
19 |
Correct |
63 ms |
127400 KB |
Output is correct |
20 |
Correct |
56 ms |
127308 KB |
Output is correct |
21 |
Correct |
61 ms |
127356 KB |
Output is correct |
22 |
Correct |
59 ms |
127316 KB |
Output is correct |
23 |
Correct |
58 ms |
127308 KB |
Output is correct |
24 |
Correct |
57 ms |
127392 KB |
Output is correct |
25 |
Correct |
65 ms |
127340 KB |
Output is correct |
26 |
Correct |
55 ms |
127328 KB |
Output is correct |
27 |
Correct |
57 ms |
127360 KB |
Output is correct |
28 |
Correct |
57 ms |
127308 KB |
Output is correct |
29 |
Correct |
66 ms |
127412 KB |
Output is correct |
30 |
Correct |
57 ms |
127408 KB |
Output is correct |
31 |
Correct |
57 ms |
127300 KB |
Output is correct |
32 |
Correct |
54 ms |
127392 KB |
Output is correct |
33 |
Correct |
69 ms |
127328 KB |
Output is correct |
34 |
Correct |
58 ms |
127352 KB |
Output is correct |
35 |
Correct |
55 ms |
127404 KB |
Output is correct |
36 |
Correct |
53 ms |
127360 KB |
Output is correct |
37 |
Correct |
57 ms |
127436 KB |
Output is correct |
38 |
Correct |
57 ms |
127424 KB |
Output is correct |
39 |
Correct |
58 ms |
127292 KB |
Output is correct |
40 |
Correct |
59 ms |
127340 KB |
Output is correct |
41 |
Correct |
70 ms |
127408 KB |
Output is correct |
42 |
Correct |
63 ms |
127312 KB |
Output is correct |
43 |
Correct |
69 ms |
127348 KB |
Output is correct |
44 |
Correct |
62 ms |
127304 KB |
Output is correct |
45 |
Correct |
77 ms |
127436 KB |
Output is correct |
46 |
Correct |
67 ms |
127316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
127308 KB |
Output is correct |
2 |
Correct |
53 ms |
127364 KB |
Output is correct |
3 |
Correct |
51 ms |
127308 KB |
Output is correct |
4 |
Correct |
54 ms |
127352 KB |
Output is correct |
5 |
Correct |
56 ms |
127296 KB |
Output is correct |
6 |
Correct |
54 ms |
127372 KB |
Output is correct |
7 |
Correct |
57 ms |
127320 KB |
Output is correct |
8 |
Correct |
53 ms |
127312 KB |
Output is correct |
9 |
Correct |
52 ms |
127328 KB |
Output is correct |
10 |
Correct |
55 ms |
127360 KB |
Output is correct |
11 |
Correct |
54 ms |
127332 KB |
Output is correct |
12 |
Correct |
57 ms |
127292 KB |
Output is correct |
13 |
Correct |
64 ms |
127308 KB |
Output is correct |
14 |
Correct |
52 ms |
127320 KB |
Output is correct |
15 |
Correct |
54 ms |
127312 KB |
Output is correct |
16 |
Correct |
62 ms |
127352 KB |
Output is correct |
17 |
Correct |
58 ms |
127388 KB |
Output is correct |
18 |
Correct |
57 ms |
127328 KB |
Output is correct |
19 |
Correct |
54 ms |
127380 KB |
Output is correct |
20 |
Correct |
63 ms |
127356 KB |
Output is correct |
21 |
Correct |
54 ms |
127288 KB |
Output is correct |
22 |
Correct |
53 ms |
127424 KB |
Output is correct |
23 |
Correct |
52 ms |
127312 KB |
Output is correct |
24 |
Correct |
57 ms |
127356 KB |
Output is correct |
25 |
Correct |
60 ms |
127360 KB |
Output is correct |
26 |
Correct |
53 ms |
127320 KB |
Output is correct |
27 |
Correct |
53 ms |
127396 KB |
Output is correct |
28 |
Correct |
56 ms |
127360 KB |
Output is correct |
29 |
Correct |
53 ms |
127348 KB |
Output is correct |
30 |
Correct |
62 ms |
127300 KB |
Output is correct |
31 |
Correct |
58 ms |
127364 KB |
Output is correct |
32 |
Correct |
56 ms |
127396 KB |
Output is correct |
33 |
Correct |
52 ms |
127364 KB |
Output is correct |
34 |
Correct |
53 ms |
127304 KB |
Output is correct |
35 |
Correct |
53 ms |
127360 KB |
Output is correct |
36 |
Correct |
82 ms |
127372 KB |
Output is correct |
37 |
Correct |
63 ms |
127400 KB |
Output is correct |
38 |
Correct |
56 ms |
127308 KB |
Output is correct |
39 |
Correct |
61 ms |
127356 KB |
Output is correct |
40 |
Correct |
59 ms |
127316 KB |
Output is correct |
41 |
Correct |
58 ms |
127308 KB |
Output is correct |
42 |
Correct |
57 ms |
127392 KB |
Output is correct |
43 |
Correct |
65 ms |
127340 KB |
Output is correct |
44 |
Correct |
55 ms |
127328 KB |
Output is correct |
45 |
Correct |
57 ms |
127360 KB |
Output is correct |
46 |
Correct |
57 ms |
127308 KB |
Output is correct |
47 |
Correct |
66 ms |
127412 KB |
Output is correct |
48 |
Correct |
57 ms |
127408 KB |
Output is correct |
49 |
Correct |
57 ms |
127300 KB |
Output is correct |
50 |
Correct |
54 ms |
127392 KB |
Output is correct |
51 |
Correct |
69 ms |
127328 KB |
Output is correct |
52 |
Correct |
58 ms |
127352 KB |
Output is correct |
53 |
Correct |
55 ms |
127404 KB |
Output is correct |
54 |
Correct |
53 ms |
127360 KB |
Output is correct |
55 |
Correct |
57 ms |
127436 KB |
Output is correct |
56 |
Correct |
57 ms |
127424 KB |
Output is correct |
57 |
Correct |
58 ms |
127292 KB |
Output is correct |
58 |
Correct |
59 ms |
127340 KB |
Output is correct |
59 |
Correct |
70 ms |
127408 KB |
Output is correct |
60 |
Correct |
63 ms |
127312 KB |
Output is correct |
61 |
Correct |
69 ms |
127348 KB |
Output is correct |
62 |
Correct |
62 ms |
127304 KB |
Output is correct |
63 |
Correct |
77 ms |
127436 KB |
Output is correct |
64 |
Correct |
67 ms |
127316 KB |
Output is correct |
65 |
Correct |
65 ms |
127384 KB |
Output is correct |
66 |
Correct |
70 ms |
127408 KB |
Output is correct |
67 |
Correct |
70 ms |
127408 KB |
Output is correct |
68 |
Correct |
71 ms |
127320 KB |
Output is correct |
69 |
Correct |
71 ms |
127300 KB |
Output is correct |
70 |
Correct |
72 ms |
127436 KB |
Output is correct |
71 |
Correct |
65 ms |
127416 KB |
Output is correct |
72 |
Correct |
69 ms |
127404 KB |
Output is correct |
73 |
Correct |
68 ms |
127300 KB |
Output is correct |
74 |
Correct |
65 ms |
127368 KB |
Output is correct |
75 |
Correct |
72 ms |
127416 KB |
Output is correct |
76 |
Correct |
75 ms |
127308 KB |
Output is correct |
77 |
Correct |
66 ms |
127324 KB |
Output is correct |
78 |
Correct |
65 ms |
127324 KB |
Output is correct |
79 |
Correct |
63 ms |
127348 KB |
Output is correct |
80 |
Correct |
67 ms |
127300 KB |
Output is correct |
81 |
Correct |
65 ms |
127360 KB |
Output is correct |
82 |
Correct |
67 ms |
127412 KB |
Output is correct |
83 |
Correct |
72 ms |
127408 KB |
Output is correct |
84 |
Correct |
69 ms |
127308 KB |
Output is correct |
85 |
Correct |
69 ms |
127364 KB |
Output is correct |
86 |
Correct |
68 ms |
127332 KB |
Output is correct |
87 |
Correct |
70 ms |
127432 KB |
Output is correct |
88 |
Correct |
69 ms |
127504 KB |
Output is correct |
89 |
Correct |
89 ms |
127416 KB |
Output is correct |
90 |
Correct |
69 ms |
127372 KB |
Output is correct |
91 |
Correct |
68 ms |
127368 KB |
Output is correct |
92 |
Correct |
69 ms |
127412 KB |
Output is correct |
93 |
Correct |
69 ms |
127460 KB |
Output is correct |