#include <bits/stdc++.h>
#include "homecoming.h"
using namespace std;
const long long INF = 1e18;
long long dp[6000005][2];
long long a[6000005],initb[6000005],b[6000005];
long long prefb[6000005];
long long calc(int N, int K, int p)
{
long long aux=0;
for(int i=1;i<=N;i++)
{
if(i>=N-p+1)
{
b[i] = b[i+N] = 0;
aux += initb[i];
}
else
b[i] = b[i+N] = initb[i];
}
for(int i=1;i<=2*N;i++)
{
prefb[i] = prefb[i-1] + b[i];
}
for(int i=0;i<K;i++)
{
dp[i][0]=0;
dp[i][1]=-INF;
}
for(int i=K;i<N+K;i++)
{
dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
dp[i][1] = max(dp[i-1][1]+a[i]-b[i], dp[i-K][0]+a[i]-(prefb[i]-prefb[i-K]));
}
return max(dp[N+K-1][0], dp[N+K-1][1]) - aux;
}
long long int solve(int N, int K, int *copA, int *copB)
{
for(int i=0;i<N;i++)
{
a[i+K] = copA[i];
initb[i+1] = copB[i];
}
long long rez=0;
for(int p=0;p<=K;p++)
rez = max(rez, calc(N,K,p));
return rez;
}
# |
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 |
Correct |
50 ms |
45032 KB |
Output is correct |
2 |
Incorrect |
11 ms |
856 KB |
Output isn't correct |
3 |
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 |
- |