#include <bits/stdc++.h>
using namespace std;
#define pos first
#define tim second
#define int long long int
const int INF = 1e18;
int32_t main() {
int n, l;
cin>>n>>l;
vector<pair<int,int>> stamps(n+2);
stamps[0] = {0,INF};
for (int i = 1; i<=n; i++) cin>>stamps[i].pos;
for (int i = 1; i<=n; i++) cin>>stamps[i].tim;
stamps[n+1] = {l, INF};
int ldp[n+5][n+5][n+5], rdp[n+5][n+5][n+5];
// whenever we move if we are moving optimally we will cover a range L, R (taking some stamps)
// ldp[L][R][i] - min time when covered L to R and we are at left end and taken i stamps
// rdp[L][R][i] - same but we are at right end
for (int i = 0; i <= n+1; i++) for (int j = 0; j <= n+1; j++) for (int k = 0; k <= n; k++) ldp[i][j][k] = rdp[i][j][k] = INF;
ldp[0][n+1][0] = rdp[0][n+1][0] = 0;
for (int L = 0; L <= n; L++) {
for (int R = n+1; R >= L+2; R--) {
for (int k = 0; k <= n; k++) {
// go L to L+1, go from R to L+1
int tl = min(ldp[L][R][k]+stamps[L+1].pos-stamps[L].pos, rdp[L][R][k]+(l-stamps[R].pos)+stamps[L+1].pos);
// go L to R-1, go from R to R-1
int tr = min(ldp[L][R][k]+(l-stamps[R-1].pos)+stamps[L].pos, rdp[L][R][k]+stamps[R].pos-stamps[R-1].pos);
// will we be able to take R-1 or L+1 stamp? check and update
ldp[L+1][R][k+(tl<=stamps[L+1].tim)] = min(ldp[L+1][R][k+(tl<=stamps[L+1].tim)], tl);
rdp[L][R-1][k+(tr<=stamps[R-1].tim)] = min(rdp[L][R-1][k+(tr<=stamps[R-1].tim)], tr);
}
}
}
int ans = 0;
for (int i = 0; i <= n+1; i++) {
for (int j = 0; j <= n+1; j++) {
for (int k = 0; k <= n; k++) {
if (ldp[i][j][k] != INF || rdp[i][j][k] != INF) ans = max(ans, k);
}
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
104 ms |
96060 KB |
Output is correct |
19 |
Correct |
55 ms |
46080 KB |
Output is correct |
20 |
Correct |
20 ms |
18412 KB |
Output is correct |
21 |
Correct |
47 ms |
42476 KB |
Output is correct |
22 |
Correct |
68 ms |
62060 KB |
Output is correct |
23 |
Correct |
16 ms |
14572 KB |
Output is correct |
24 |
Correct |
11 ms |
10220 KB |
Output is correct |
25 |
Correct |
18 ms |
14188 KB |
Output is correct |
26 |
Correct |
5 ms |
3692 KB |
Output is correct |
27 |
Correct |
20 ms |
15084 KB |
Output is correct |
28 |
Correct |
13 ms |
9324 KB |
Output is correct |
29 |
Correct |
19 ms |
15468 KB |
Output is correct |
30 |
Correct |
12 ms |
10988 KB |
Output is correct |
31 |
Correct |
16 ms |
14188 KB |
Output is correct |
32 |
Correct |
7 ms |
5740 KB |
Output is correct |
33 |
Correct |
16 ms |
14188 KB |
Output is correct |
34 |
Correct |
4 ms |
3308 KB |
Output is correct |
35 |
Correct |
16 ms |
13676 KB |
Output is correct |
36 |
Correct |
5 ms |
4844 KB |
Output is correct |
37 |
Correct |
17 ms |
15084 KB |
Output is correct |
38 |
Correct |
8 ms |
6380 KB |
Output is correct |
39 |
Correct |
18 ms |
15980 KB |
Output is correct |
40 |
Correct |
8 ms |
7404 KB |
Output is correct |
41 |
Correct |
140 ms |
131056 KB |
Output is correct |
42 |
Correct |
77 ms |
73196 KB |
Output is correct |
43 |
Correct |
139 ms |
130924 KB |
Output is correct |
44 |
Correct |
76 ms |
71916 KB |
Output is correct |
45 |
Correct |
140 ms |
131116 KB |
Output is correct |
46 |
Correct |
80 ms |
73196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
104 ms |
96060 KB |
Output is correct |
37 |
Correct |
55 ms |
46080 KB |
Output is correct |
38 |
Correct |
20 ms |
18412 KB |
Output is correct |
39 |
Correct |
47 ms |
42476 KB |
Output is correct |
40 |
Correct |
68 ms |
62060 KB |
Output is correct |
41 |
Correct |
16 ms |
14572 KB |
Output is correct |
42 |
Correct |
11 ms |
10220 KB |
Output is correct |
43 |
Correct |
18 ms |
14188 KB |
Output is correct |
44 |
Correct |
5 ms |
3692 KB |
Output is correct |
45 |
Correct |
20 ms |
15084 KB |
Output is correct |
46 |
Correct |
13 ms |
9324 KB |
Output is correct |
47 |
Correct |
19 ms |
15468 KB |
Output is correct |
48 |
Correct |
12 ms |
10988 KB |
Output is correct |
49 |
Correct |
16 ms |
14188 KB |
Output is correct |
50 |
Correct |
7 ms |
5740 KB |
Output is correct |
51 |
Correct |
16 ms |
14188 KB |
Output is correct |
52 |
Correct |
4 ms |
3308 KB |
Output is correct |
53 |
Correct |
16 ms |
13676 KB |
Output is correct |
54 |
Correct |
5 ms |
4844 KB |
Output is correct |
55 |
Correct |
17 ms |
15084 KB |
Output is correct |
56 |
Correct |
8 ms |
6380 KB |
Output is correct |
57 |
Correct |
18 ms |
15980 KB |
Output is correct |
58 |
Correct |
8 ms |
7404 KB |
Output is correct |
59 |
Correct |
140 ms |
131056 KB |
Output is correct |
60 |
Correct |
77 ms |
73196 KB |
Output is correct |
61 |
Correct |
139 ms |
130924 KB |
Output is correct |
62 |
Correct |
76 ms |
71916 KB |
Output is correct |
63 |
Correct |
140 ms |
131116 KB |
Output is correct |
64 |
Correct |
80 ms |
73196 KB |
Output is correct |
65 |
Correct |
123 ms |
112688 KB |
Output is correct |
66 |
Correct |
106 ms |
99308 KB |
Output is correct |
67 |
Correct |
100 ms |
93036 KB |
Output is correct |
68 |
Correct |
90 ms |
82796 KB |
Output is correct |
69 |
Correct |
121 ms |
110956 KB |
Output is correct |
70 |
Correct |
117 ms |
104172 KB |
Output is correct |
71 |
Correct |
110 ms |
105964 KB |
Output is correct |
72 |
Correct |
114 ms |
107500 KB |
Output is correct |
73 |
Correct |
104 ms |
96108 KB |
Output is correct |
74 |
Correct |
99 ms |
87148 KB |
Output is correct |
75 |
Correct |
112 ms |
101100 KB |
Output is correct |
76 |
Correct |
133 ms |
123404 KB |
Output is correct |
77 |
Correct |
136 ms |
123348 KB |
Output is correct |
78 |
Correct |
104 ms |
84204 KB |
Output is correct |
79 |
Correct |
95 ms |
88556 KB |
Output is correct |
80 |
Correct |
130 ms |
119788 KB |
Output is correct |
81 |
Correct |
96 ms |
89964 KB |
Output is correct |
82 |
Correct |
117 ms |
97644 KB |
Output is correct |
83 |
Correct |
138 ms |
130924 KB |
Output is correct |
84 |
Correct |
112 ms |
104172 KB |
Output is correct |
85 |
Correct |
124 ms |
117996 KB |
Output is correct |
86 |
Correct |
123 ms |
114412 KB |
Output is correct |
87 |
Correct |
108 ms |
100844 KB |
Output is correct |
88 |
Correct |
141 ms |
132844 KB |
Output is correct |
89 |
Correct |
141 ms |
132972 KB |
Output is correct |
90 |
Correct |
108 ms |
102508 KB |
Output is correct |
91 |
Correct |
144 ms |
132972 KB |
Output is correct |
92 |
Correct |
147 ms |
132844 KB |
Output is correct |
93 |
Correct |
138 ms |
129004 KB |
Output is correct |