#include "homecoming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = (int)2e6 + 7;
const ll linf = (ll)1e18 + 7;
ll pref[N + N];
ll dp[N][2][2];
ll get(int l, int r) {
return pref[r] - pref[l - 1];
}
ll solve(int n, int k, int a[], int b[]) {
pref[0] = b[0];
for (int i = 0; i < n + n; i++) {
pref[i + 1] = pref[i] + b[(i + 1) % n];
}
for (int i = 0; i < N; i++)
for (int j = 0; j < 2; j++)
for (int l = 0; l < 2; l++)
dp[i][j][l] = -linf;
dp[0][1][1] = a[0] - pref[k - 1];
dp[0][0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 2; j++) {
dp[i][0][j] = max(dp[i - 1][0][j], dp[i - 1][1][j]);
if (j == 0 || i + k - 1 < n) {
dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, i + k - 1), dp[i - 1][1][j] + a[i] - b[(i + k - 1) % n]);
} else {
dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, n - 1), dp[i - 1][1][j] + a[i]);
}
// cout << i << ' ' << j << ' ' << dp[i][0][j] << ' ' << dp[i][1][j] << endl;
}
}
ll ans = 0;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
ans = max(ans, dp[n - 1][i][j]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
62968 KB |
Output is correct |
2 |
Correct |
47 ms |
63076 KB |
Output is correct |
3 |
Correct |
213 ms |
63124 KB |
Output is correct |
4 |
Correct |
48 ms |
63204 KB |
Output is correct |
5 |
Correct |
92 ms |
63268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
62968 KB |
Output is correct |
2 |
Correct |
47 ms |
63076 KB |
Output is correct |
3 |
Correct |
213 ms |
63124 KB |
Output is correct |
4 |
Correct |
48 ms |
63204 KB |
Output is correct |
5 |
Correct |
92 ms |
63268 KB |
Output is correct |
6 |
Correct |
49 ms |
63276 KB |
Output is correct |
7 |
Correct |
50 ms |
63276 KB |
Output is correct |
8 |
Correct |
89 ms |
63280 KB |
Output is correct |
9 |
Correct |
48 ms |
63316 KB |
Output is correct |
10 |
Execution timed out |
1085 ms |
63316 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
74908 KB |
Output is correct |
2 |
Correct |
396 ms |
74908 KB |
Output is correct |
3 |
Correct |
238 ms |
110132 KB |
Output is correct |
4 |
Correct |
50 ms |
110132 KB |
Output is correct |
5 |
Execution timed out |
1062 ms |
110132 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
62968 KB |
Output is correct |
2 |
Correct |
47 ms |
63076 KB |
Output is correct |
3 |
Correct |
213 ms |
63124 KB |
Output is correct |
4 |
Correct |
48 ms |
63204 KB |
Output is correct |
5 |
Correct |
92 ms |
63268 KB |
Output is correct |
6 |
Correct |
49 ms |
63276 KB |
Output is correct |
7 |
Correct |
50 ms |
63276 KB |
Output is correct |
8 |
Correct |
89 ms |
63280 KB |
Output is correct |
9 |
Correct |
48 ms |
63316 KB |
Output is correct |
10 |
Execution timed out |
1085 ms |
63316 KB |
Time limit exceeded |