#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 205;
int n, l, tim, x[maxN], t[maxN], dp[maxN][maxN][maxN][2];
void solve() {
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) cin >> t[i];
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j++) {
for (int k = 0; k <= n; k++) {
dp[i][j][k][0] = dp[i][j][k][1] = inf;
}
}
} x[n + 1] = l; dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
for (int i = 0; i <= n; i++) {
for (int j = n + 1; j > i; j--) {
for (int k = 0; k <= n; k++) {
tim = dp[i][j][k][0] + x[i + 1] - x[i];
if (tim <= t[i + 1]) dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], tim);
else dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], tim);
tim = dp[i][j][k][1] + x[i + 1] - x[j] + l;
if (tim <= t[i + 1]) dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], tim);
else dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], tim);
tim = dp[i][j][k][0] + x[i] - x[j - 1] + l;
if (tim <= t[j - 1]) dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], tim);
else dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], tim);
tim = dp[i][j][k][1] + x[j] - x[j - 1];
if (tim <= t[j - 1]) dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], tim);
else dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], tim);
}
}
} int ans = 0;
for (int i = 0; i <= n; i++) {
for (int j = n + 1; j > i; j--) {
for (int k = 0; k <= n; k++) {
if (dp[i][j][k][0] != inf) ans = max(ans, k);
if (dp[i][j][k][1] != inf) ans = max(ans, k);
}
}
} cout << ans;
}
int32_t main() {
// ios_base::sync_with_stdio(false);
// cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Compilation message
ho_t3.cpp: In function 'void open_file(std::string)':
ho_t3.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
528 KB |
Output is correct |
6 |
Correct |
0 ms |
700 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
528 KB |
Output is correct |
6 |
Correct |
0 ms |
700 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
860 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
860 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
860 KB |
Output is correct |
26 |
Correct |
0 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
616 KB |
Output is correct |
29 |
Correct |
1 ms |
856 KB |
Output is correct |
30 |
Correct |
0 ms |
956 KB |
Output is correct |
31 |
Correct |
0 ms |
860 KB |
Output is correct |
32 |
Correct |
0 ms |
860 KB |
Output is correct |
33 |
Correct |
0 ms |
860 KB |
Output is correct |
34 |
Correct |
0 ms |
860 KB |
Output is correct |
35 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
528 KB |
Output is correct |
6 |
Correct |
0 ms |
700 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
42 ms |
53584 KB |
Output is correct |
19 |
Correct |
22 ms |
32600 KB |
Output is correct |
20 |
Correct |
11 ms |
17756 KB |
Output is correct |
21 |
Correct |
20 ms |
31060 KB |
Output is correct |
22 |
Correct |
29 ms |
40028 KB |
Output is correct |
23 |
Correct |
9 ms |
15196 KB |
Output is correct |
24 |
Correct |
7 ms |
11868 KB |
Output is correct |
25 |
Correct |
9 ms |
14940 KB |
Output is correct |
26 |
Correct |
4 ms |
5980 KB |
Output is correct |
27 |
Correct |
9 ms |
15452 KB |
Output is correct |
28 |
Correct |
5 ms |
11236 KB |
Output is correct |
29 |
Correct |
9 ms |
15708 KB |
Output is correct |
30 |
Correct |
7 ms |
12380 KB |
Output is correct |
31 |
Correct |
10 ms |
14940 KB |
Output is correct |
32 |
Correct |
4 ms |
8028 KB |
Output is correct |
33 |
Correct |
9 ms |
14716 KB |
Output is correct |
34 |
Correct |
2 ms |
5468 KB |
Output is correct |
35 |
Correct |
8 ms |
14580 KB |
Output is correct |
36 |
Correct |
4 ms |
7004 KB |
Output is correct |
37 |
Correct |
9 ms |
15452 KB |
Output is correct |
38 |
Correct |
5 ms |
8540 KB |
Output is correct |
39 |
Correct |
9 ms |
15964 KB |
Output is correct |
40 |
Correct |
5 ms |
9560 KB |
Output is correct |
41 |
Correct |
52 ms |
65840 KB |
Output is correct |
42 |
Correct |
31 ms |
44632 KB |
Output is correct |
43 |
Correct |
57 ms |
65880 KB |
Output is correct |
44 |
Correct |
31 ms |
44216 KB |
Output is correct |
45 |
Correct |
54 ms |
65880 KB |
Output is correct |
46 |
Correct |
31 ms |
44636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
528 KB |
Output is correct |
6 |
Correct |
0 ms |
700 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
860 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
860 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
860 KB |
Output is correct |
26 |
Correct |
0 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
616 KB |
Output is correct |
29 |
Correct |
1 ms |
856 KB |
Output is correct |
30 |
Correct |
0 ms |
956 KB |
Output is correct |
31 |
Correct |
0 ms |
860 KB |
Output is correct |
32 |
Correct |
0 ms |
860 KB |
Output is correct |
33 |
Correct |
0 ms |
860 KB |
Output is correct |
34 |
Correct |
0 ms |
860 KB |
Output is correct |
35 |
Correct |
1 ms |
860 KB |
Output is correct |
36 |
Correct |
42 ms |
53584 KB |
Output is correct |
37 |
Correct |
22 ms |
32600 KB |
Output is correct |
38 |
Correct |
11 ms |
17756 KB |
Output is correct |
39 |
Correct |
20 ms |
31060 KB |
Output is correct |
40 |
Correct |
29 ms |
40028 KB |
Output is correct |
41 |
Correct |
9 ms |
15196 KB |
Output is correct |
42 |
Correct |
7 ms |
11868 KB |
Output is correct |
43 |
Correct |
9 ms |
14940 KB |
Output is correct |
44 |
Correct |
4 ms |
5980 KB |
Output is correct |
45 |
Correct |
9 ms |
15452 KB |
Output is correct |
46 |
Correct |
5 ms |
11236 KB |
Output is correct |
47 |
Correct |
9 ms |
15708 KB |
Output is correct |
48 |
Correct |
7 ms |
12380 KB |
Output is correct |
49 |
Correct |
10 ms |
14940 KB |
Output is correct |
50 |
Correct |
4 ms |
8028 KB |
Output is correct |
51 |
Correct |
9 ms |
14716 KB |
Output is correct |
52 |
Correct |
2 ms |
5468 KB |
Output is correct |
53 |
Correct |
8 ms |
14580 KB |
Output is correct |
54 |
Correct |
4 ms |
7004 KB |
Output is correct |
55 |
Correct |
9 ms |
15452 KB |
Output is correct |
56 |
Correct |
5 ms |
8540 KB |
Output is correct |
57 |
Correct |
9 ms |
15964 KB |
Output is correct |
58 |
Correct |
5 ms |
9560 KB |
Output is correct |
59 |
Correct |
52 ms |
65840 KB |
Output is correct |
60 |
Correct |
31 ms |
44632 KB |
Output is correct |
61 |
Correct |
57 ms |
65880 KB |
Output is correct |
62 |
Correct |
31 ms |
44216 KB |
Output is correct |
63 |
Correct |
54 ms |
65880 KB |
Output is correct |
64 |
Correct |
31 ms |
44636 KB |
Output is correct |
65 |
Correct |
53 ms |
59664 KB |
Output is correct |
66 |
Correct |
51 ms |
54876 KB |
Output is correct |
67 |
Correct |
39 ms |
52316 KB |
Output is correct |
68 |
Correct |
35 ms |
48476 KB |
Output is correct |
69 |
Correct |
46 ms |
58964 KB |
Output is correct |
70 |
Correct |
56 ms |
56668 KB |
Output is correct |
71 |
Correct |
47 ms |
57172 KB |
Output is correct |
72 |
Correct |
44 ms |
57692 KB |
Output is correct |
73 |
Correct |
39 ms |
53596 KB |
Output is correct |
74 |
Correct |
34 ms |
50012 KB |
Output is correct |
75 |
Correct |
41 ms |
55384 KB |
Output is correct |
76 |
Correct |
49 ms |
63312 KB |
Output is correct |
77 |
Correct |
56 ms |
63324 KB |
Output is correct |
78 |
Correct |
35 ms |
48984 KB |
Output is correct |
79 |
Correct |
38 ms |
50756 KB |
Output is correct |
80 |
Correct |
50 ms |
62040 KB |
Output is correct |
81 |
Correct |
38 ms |
51288 KB |
Output is correct |
82 |
Correct |
40 ms |
54108 KB |
Output is correct |
83 |
Correct |
53 ms |
65880 KB |
Output is correct |
84 |
Correct |
45 ms |
56420 KB |
Output is correct |
85 |
Correct |
47 ms |
61532 KB |
Output is correct |
86 |
Correct |
46 ms |
60240 KB |
Output is correct |
87 |
Correct |
41 ms |
55384 KB |
Output is correct |
88 |
Correct |
56 ms |
66652 KB |
Output is correct |
89 |
Correct |
57 ms |
66652 KB |
Output is correct |
90 |
Correct |
43 ms |
55932 KB |
Output is correct |
91 |
Correct |
54 ms |
66640 KB |
Output is correct |
92 |
Correct |
53 ms |
66648 KB |
Output is correct |
93 |
Correct |
52 ms |
65364 KB |
Output is correct |