#ifndef EVAL
#include "homecoming.h"
#endif
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll dp[N][2], pa[N], pb[N];
ll solve(int n, int k, int a[], int b[]){
for(int i=0;i<n;i++){
pa[i] = a[i];
if(i) pa[i] += pa[i-1];
pb[i] = b[i];
if(i) pb[i] += pb[i-1];
}
memset(dp, 254, sizeof dp);
dp[0][1] = a[0] - pb[k - 1];
for(int i=1;i<n;i++){
dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
dp[i][1] = max(dp[i-1][1] + a[i] - (i + k - 1 < n ? b[i + k - 1] : 0),
dp[i-1][0] + a[i] - (pb[min(i + k - 1, n - 1)] - pb[i - 1]));
}
ll res = max(dp[n - 1][0], dp[n - 1][1]);
memset(dp, 254, sizeof dp);
dp[0][0] = 0;
for(int i=1;i<n;i++){
dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
dp[i][1] = max(dp[i-1][1] + a[i] - b[(i + k - 1) % n],
dp[i-1][0] + a[i] - (pb[min(i + k - 1, n - 1)] - pb[i - 1] + (i + k > n ? pb[i + k - 1 - n] : 0)));
}
res = max({res, dp[n - 1][0], dp[n - 1][1]});
return res;
}
/*
1
3 2
40 80 100
140 0 20
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
4 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3420 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
4 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3420 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3668 KB |
Output is correct |
7 |
Correct |
2 ms |
3668 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
9 |
Correct |
2 ms |
3540 KB |
Output is correct |
10 |
Correct |
145 ms |
3560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
33 ms |
21228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3456 KB |
Output is correct |
3 |
Correct |
4 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3420 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3668 KB |
Output is correct |
7 |
Correct |
2 ms |
3668 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
9 |
Correct |
2 ms |
3540 KB |
Output is correct |
10 |
Correct |
145 ms |
3560 KB |
Output is correct |
11 |
Runtime error |
33 ms |
21228 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |