#include <bits/stdc++.h>
//ako ovaj vaso daso misli da me pobedjuje.....
using namespace std;
#define int long long
#define f first
#define s second
const int N = 210;
const int inf = 1e18;
int n, l, x[N], t[N], dp[N][N][N][2];
//prvih i, poslednjih j, pokupio, i/j
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> l;
for (int i = 1;i <= n;i++) {
cin >> x[i];
}
for (int i = 1;i <= n;i++) {
cin >> t[i];
}
x[n + 1] = l;
for (int i = 0;i <= n;i++) {
for (int j = 0;j <= n;j++) {
for (int k = 0;k <= n;k++)
dp[i][j][k][0] = dp[i][j][k][1] = inf;
}
}
dp[0][0][0][0] = dp[0][0][0][1] = 0;
int ans = 0;
for (int cnt = 0;cnt <= n;cnt++) {
for (int i = 0;i <= n;i++) {
for (int j = 0;j <= n;j++) {
if (i + j > n)
break;
if (i > 0) {
dp[i][j][cnt][0] = min(dp[i][j][cnt][0], dp[i - 1][j][cnt][0] + x[i] - x[i - 1]);
dp[i][j][cnt][0] = min(dp[i][j][cnt][0], dp[i - 1][j][cnt][1] + x[i] + (l - x[n - j + 1]));
if (cnt > 0) {
int time1 = dp[i - 1][j][cnt - 1][0] + x[i] - x[i - 1];
int time2 = dp[i - 1][j][cnt - 1][1] + x[i] + (l - x[n - j + 1]);
int time = min(time1, time2);
if (time <= t[i])
dp[i][j][cnt][0] = min(dp[i][j][cnt][0], time);
}
}
if (j > 0) {
dp[i][j][cnt][1] = min(dp[i][j][cnt][1], dp[i][j - 1][cnt][1] + x[n - j + 2] - x[n - j + 1]);
dp[i][j][cnt][1] = min(dp[i][j][cnt][1], dp[i][j - 1][cnt][0] + x[i] + (l - x[n - j + 1]));
if (cnt > 0) {
int time1 = dp[i][j - 1][cnt - 1][1] + x[n - j + 2] - x[n - j + 1];
int time2 = dp[i][j - 1][cnt - 1][0] + x[i] + (l - x[n - j + 1]);
int time = min(time1, time2);
if (time <= t[n - j + 1])
dp[i][j][cnt][1] = min(dp[i][j][cnt][1], time);
}
}
if (dp[i][j][cnt][0] != inf || dp[i][j][cnt][1] != inf)
ans = cnt;
}
}
}
cout << ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
10840 KB |
Output is correct |
22 |
Correct |
1 ms |
6640 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10756 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
6488 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
3 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
51 ms |
125816 KB |
Output is correct |
19 |
Correct |
35 ms |
96860 KB |
Output is correct |
20 |
Correct |
18 ms |
72288 KB |
Output is correct |
21 |
Correct |
29 ms |
94816 KB |
Output is correct |
22 |
Correct |
38 ms |
107352 KB |
Output is correct |
23 |
Correct |
15 ms |
66144 KB |
Output is correct |
24 |
Correct |
12 ms |
57952 KB |
Output is correct |
25 |
Correct |
14 ms |
66320 KB |
Output is correct |
26 |
Correct |
7 ms |
39528 KB |
Output is correct |
27 |
Correct |
15 ms |
66244 KB |
Output is correct |
28 |
Correct |
13 ms |
55896 KB |
Output is correct |
29 |
Correct |
16 ms |
68188 KB |
Output is correct |
30 |
Correct |
13 ms |
60008 KB |
Output is correct |
31 |
Correct |
16 ms |
66188 KB |
Output is correct |
32 |
Correct |
9 ms |
47708 KB |
Output is correct |
33 |
Correct |
16 ms |
66140 KB |
Output is correct |
34 |
Correct |
7 ms |
39512 KB |
Output is correct |
35 |
Correct |
14 ms |
64088 KB |
Output is correct |
36 |
Correct |
8 ms |
43612 KB |
Output is correct |
37 |
Correct |
15 ms |
66140 KB |
Output is correct |
38 |
Correct |
9 ms |
49756 KB |
Output is correct |
39 |
Correct |
16 ms |
68188 KB |
Output is correct |
40 |
Correct |
10 ms |
51804 KB |
Output is correct |
41 |
Correct |
66 ms |
140112 KB |
Output is correct |
42 |
Correct |
45 ms |
115800 KB |
Output is correct |
43 |
Correct |
68 ms |
139952 KB |
Output is correct |
44 |
Correct |
41 ms |
113500 KB |
Output is correct |
45 |
Correct |
65 ms |
139912 KB |
Output is correct |
46 |
Correct |
42 ms |
115548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
10840 KB |
Output is correct |
22 |
Correct |
1 ms |
6640 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10756 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
6488 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
3 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10712 KB |
Output is correct |
36 |
Correct |
51 ms |
125816 KB |
Output is correct |
37 |
Correct |
35 ms |
96860 KB |
Output is correct |
38 |
Correct |
18 ms |
72288 KB |
Output is correct |
39 |
Correct |
29 ms |
94816 KB |
Output is correct |
40 |
Correct |
38 ms |
107352 KB |
Output is correct |
41 |
Correct |
15 ms |
66144 KB |
Output is correct |
42 |
Correct |
12 ms |
57952 KB |
Output is correct |
43 |
Correct |
14 ms |
66320 KB |
Output is correct |
44 |
Correct |
7 ms |
39528 KB |
Output is correct |
45 |
Correct |
15 ms |
66244 KB |
Output is correct |
46 |
Correct |
13 ms |
55896 KB |
Output is correct |
47 |
Correct |
16 ms |
68188 KB |
Output is correct |
48 |
Correct |
13 ms |
60008 KB |
Output is correct |
49 |
Correct |
16 ms |
66188 KB |
Output is correct |
50 |
Correct |
9 ms |
47708 KB |
Output is correct |
51 |
Correct |
16 ms |
66140 KB |
Output is correct |
52 |
Correct |
7 ms |
39512 KB |
Output is correct |
53 |
Correct |
14 ms |
64088 KB |
Output is correct |
54 |
Correct |
8 ms |
43612 KB |
Output is correct |
55 |
Correct |
15 ms |
66140 KB |
Output is correct |
56 |
Correct |
9 ms |
49756 KB |
Output is correct |
57 |
Correct |
16 ms |
68188 KB |
Output is correct |
58 |
Correct |
10 ms |
51804 KB |
Output is correct |
59 |
Correct |
66 ms |
140112 KB |
Output is correct |
60 |
Correct |
45 ms |
115800 KB |
Output is correct |
61 |
Correct |
68 ms |
139952 KB |
Output is correct |
62 |
Correct |
41 ms |
113500 KB |
Output is correct |
63 |
Correct |
65 ms |
139912 KB |
Output is correct |
64 |
Correct |
42 ms |
115548 KB |
Output is correct |
65 |
Correct |
56 ms |
131920 KB |
Output is correct |
66 |
Correct |
53 ms |
127828 KB |
Output is correct |
67 |
Correct |
51 ms |
123744 KB |
Output is correct |
68 |
Correct |
45 ms |
119640 KB |
Output is correct |
69 |
Correct |
60 ms |
131952 KB |
Output is correct |
70 |
Correct |
55 ms |
129872 KB |
Output is correct |
71 |
Correct |
54 ms |
129868 KB |
Output is correct |
72 |
Correct |
56 ms |
129876 KB |
Output is correct |
73 |
Correct |
52 ms |
125800 KB |
Output is correct |
74 |
Correct |
49 ms |
121692 KB |
Output is correct |
75 |
Correct |
54 ms |
127836 KB |
Output is correct |
76 |
Correct |
61 ms |
136016 KB |
Output is correct |
77 |
Correct |
63 ms |
136020 KB |
Output is correct |
78 |
Correct |
50 ms |
119640 KB |
Output is correct |
79 |
Correct |
55 ms |
121692 KB |
Output is correct |
80 |
Correct |
65 ms |
136020 KB |
Output is correct |
81 |
Correct |
49 ms |
123744 KB |
Output is correct |
82 |
Correct |
51 ms |
125776 KB |
Output is correct |
83 |
Correct |
70 ms |
140112 KB |
Output is correct |
84 |
Correct |
54 ms |
129876 KB |
Output is correct |
85 |
Correct |
60 ms |
134004 KB |
Output is correct |
86 |
Correct |
58 ms |
133980 KB |
Output is correct |
87 |
Correct |
53 ms |
127848 KB |
Output is correct |
88 |
Correct |
66 ms |
140160 KB |
Output is correct |
89 |
Correct |
63 ms |
140124 KB |
Output is correct |
90 |
Correct |
53 ms |
127608 KB |
Output is correct |
91 |
Correct |
65 ms |
140112 KB |
Output is correct |
92 |
Correct |
64 ms |
140120 KB |
Output is correct |
93 |
Correct |
64 ms |
138076 KB |
Output is correct |