#include <iostream>
#include <map>
using namespace std;
using ll = long long;
int n, l;
ll x[205], t[205];
map<ll, int> dp[205][205];
ll dist(int x1, int x2) {
if (x1 > x2) swap(x1, x2);
return min(x2 - x1, l - x2 + x1);
}
int solve(int i, int j, ll time_passed) {
if (abs(i - j) == 1) return 0;
if (dp[i][j].count(time_passed)) return dp[i][j][time_passed];
int cur = i, l = min(i, j), r = max(i, j);
int ans = solve(l + 1, r, dist(x[cur], x[l + 1]) + time_passed) + (dist(x[cur], x[l + 1]) + time_passed <= t[l + 1]);
ans = max(ans, solve(r - 1, l, dist(x[cur], x[r - 1]) + time_passed) + (dist(x[cur], x[r - 1]) + time_passed <= t[r - 1]));
dp[i][j][time_passed] = ans;
return ans;
}
int main() {
cin >> n >> l;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
t[0] = t[n + 1] = 0;
cout << solve(0, n + 1, 0) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
2388 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
2388 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1 ms |
2260 KB |
Output is correct |
18 |
Correct |
5 ms |
3284 KB |
Output is correct |
19 |
Correct |
1 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2516 KB |
Output is correct |
21 |
Correct |
5 ms |
3284 KB |
Output is correct |
22 |
Correct |
1 ms |
2260 KB |
Output is correct |
23 |
Correct |
10 ms |
4276 KB |
Output is correct |
24 |
Correct |
3 ms |
2772 KB |
Output is correct |
25 |
Correct |
7 ms |
3284 KB |
Output is correct |
26 |
Correct |
6 ms |
3304 KB |
Output is correct |
27 |
Correct |
2 ms |
2260 KB |
Output is correct |
28 |
Correct |
3 ms |
2260 KB |
Output is correct |
29 |
Correct |
11 ms |
4320 KB |
Output is correct |
30 |
Correct |
10 ms |
4340 KB |
Output is correct |
31 |
Correct |
5 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
2772 KB |
Output is correct |
33 |
Correct |
2 ms |
2388 KB |
Output is correct |
34 |
Correct |
2 ms |
2388 KB |
Output is correct |
35 |
Correct |
2 ms |
2404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
2388 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1 ms |
2260 KB |
Output is correct |
18 |
Execution timed out |
2112 ms |
280160 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
1 ms |
2260 KB |
Output is correct |
4 |
Correct |
1 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2388 KB |
Output is correct |
7 |
Correct |
1 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2388 KB |
Output is correct |
10 |
Correct |
1 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2388 KB |
Output is correct |
13 |
Correct |
2 ms |
2388 KB |
Output is correct |
14 |
Correct |
1 ms |
2260 KB |
Output is correct |
15 |
Correct |
1 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1 ms |
2260 KB |
Output is correct |
18 |
Correct |
5 ms |
3284 KB |
Output is correct |
19 |
Correct |
1 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2516 KB |
Output is correct |
21 |
Correct |
5 ms |
3284 KB |
Output is correct |
22 |
Correct |
1 ms |
2260 KB |
Output is correct |
23 |
Correct |
10 ms |
4276 KB |
Output is correct |
24 |
Correct |
3 ms |
2772 KB |
Output is correct |
25 |
Correct |
7 ms |
3284 KB |
Output is correct |
26 |
Correct |
6 ms |
3304 KB |
Output is correct |
27 |
Correct |
2 ms |
2260 KB |
Output is correct |
28 |
Correct |
3 ms |
2260 KB |
Output is correct |
29 |
Correct |
11 ms |
4320 KB |
Output is correct |
30 |
Correct |
10 ms |
4340 KB |
Output is correct |
31 |
Correct |
5 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
2772 KB |
Output is correct |
33 |
Correct |
2 ms |
2388 KB |
Output is correct |
34 |
Correct |
2 ms |
2388 KB |
Output is correct |
35 |
Correct |
2 ms |
2404 KB |
Output is correct |
36 |
Execution timed out |
2112 ms |
280160 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |