#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]);
}
int copA[] = {40,80,100}, copB[] = {140,0,20};
signed main()
{
cout<<solve(3, 2, copA, copB);
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccfQBVTQ.o: in function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccGLi2yP.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status