#include "homecoming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int len = 2e6+5;
const ll inf = 1e17;
int ar[len], br[len], n, k;
ll suf[len], sufa[len], sufb[len], mx[len], dp[len];
ll fix(int st){
for (int i = n-1; i >= 0; i--){
sufa[i] = ar[(st+i)%n] + sufa[i+1];
sufb[i] = br[(st+i)%n] + sufb[i+1];
}
mx[n] = dp[n] = suf[n] = 0;
for (int i = n-1; i >= 0; i--){
dp[i] = sufa[i]-sufb[i] + mx[i+1];
//for (int j = i+1; j <= n+1; j++)
// dp[i] = max(dp[i], sufa[i]-sufb[i] + sufb[j+k-1]-sufa[j]+suf[j]);
suf[i] = max(suf[i+1], dp[i]);
mx[i] = max(mx[i+1], sufb[i+k-1]-sufa[i]+suf[i]);
}
return dp[0];
}
void init(){
for (int i = 0; i < 2*n; i++)
sufa[i] = sufb[i] = 0;
}
ll solve(int N, int K, int A[], int B[]){
n = N, k = K;
for (int i = 0; i < n; i++){
ar[i] = A[i];
br[i] = B[i];
}
init();
ll ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, fix(i));
return ans;
}
/*
1
3 2
40 80 100
140 0 20
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
224 ms |
888 KB |
Output is correct |
7 |
Correct |
225 ms |
888 KB |
Output is correct |
8 |
Correct |
64 ms |
760 KB |
Output is correct |
9 |
Correct |
224 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
39792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
224 ms |
888 KB |
Output is correct |
7 |
Correct |
225 ms |
888 KB |
Output is correct |
8 |
Correct |
64 ms |
760 KB |
Output is correct |
9 |
Correct |
224 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Execution timed out |
1064 ms |
39792 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |