#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long dp[4000005][2];
long long a[4000005],b[400005];
long long prefa[4000005],prefb[4000005];
long long int solve(int N, int K, int *copA, int *copB)
{
for(int i=0;i<N;i++)
{
a[i+1] = a[i+N+1] = copA[i];
b[i+1] = b[i+N+1] = copB[i];
}
for(int i=1;i<=2*N;i++)
{
prefa[i] = prefa[i-1] + a[i];
prefb[i] = prefb[i-1] + b[i];
}
dp[0][1]=-INF;
for(int i=1;i<=N;i++)
{
dp[i][0] = dp[i][1] = -INF;
dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
dp[i][1] = max(dp[i][1], dp[i-1][1]+a[i]-b[i+K-1]);
if(i-K>=0) dp[i][1] = max(dp[i][1], max(dp[i-K][0],dp[i-K][1])+a[i]-(prefb[i+K-1]-prefb[i-1]));
else dp[i][1] = max(dp[i][1], a[i]-(prefb[i+K-1]-prefb[i-1]));
//cerr<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<" dp\n";
}
return max(dp[N][0], dp[N][1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
48096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |