#include <bits/stdc++.h>
#include "homecoming.h"
using namespace std;
typedef long long ll;
const int MAXN = 4e6 + 25;
ll dp[MAXN], pref_a[MAXN], pref_b[MAXN];
ll solve (int n, int k, int *A, int *B) {
for (int i = 0; i < 2 * n; i++) {
pref_a[i] = pref_b[i] = dp[i] = 0;
}
for (int i = 0; i < n; i++) {
pref_a[i] = A[i] + (i == 0 ? 0 : pref_a[i - 1]);
}
for (int i = 0; i < n + k; i++) {
pref_b[i] = B[i % n] + (i == 0 ? 0 : pref_b[i - 1]);
}
ll ret = 0, cur = 0;
for (int i = 0; i < n; i++) {
dp[i] = pref_a[i] - pref_b[i + k - 1] + cur;
if (i) dp[i] = max(dp[i], dp[i - 1]);
else dp[i] = max(dp[i], 0ll);
cur = max(cur, dp[i] - pref_a[i] + pref_b[i]);
ret = max(ret, dp[i]);
}
cur = 0;
for (int i = 0; i < n; i++) {
dp[i] = pref_a[i] - pref_b[min(n - 1, i + k - 1)] + cur;
if (i) dp[i] = max(dp[i], dp[i - 1]);
cur = max(cur, dp[i] - pref_a[i] + pref_b[i]);
}
ret = max(ret, dp[n - 1]);
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4572 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4572 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4572 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
31068 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
150 ms |
149412 KB |
Output is correct |
4 |
Correct |
2 ms |
7000 KB |
Output is correct |
5 |
Correct |
8 ms |
9008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4600 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4572 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4572 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
28 ms |
31068 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Correct |
150 ms |
149412 KB |
Output is correct |
14 |
Correct |
2 ms |
7000 KB |
Output is correct |
15 |
Correct |
8 ms |
9008 KB |
Output is correct |
16 |
Correct |
121 ms |
149736 KB |
Output is correct |
17 |
Correct |
58 ms |
36728 KB |
Output is correct |
18 |
Correct |
110 ms |
46996 KB |
Output is correct |
19 |
Correct |
91 ms |
86988 KB |
Output is correct |
20 |
Correct |
89 ms |
132716 KB |
Output is correct |
21 |
Correct |
88 ms |
84524 KB |
Output is correct |