#include <bits/stdc++.h>
//#include "homecoming.h"
using namespace std;
const long long INF = 1e18;
long long dp[6000005][2];
long long a[6000005],b[6000005];
long long prefa[6000005],prefb[6000005];
long long int solve(int N, int K, int *copA, int *copB)
{
for(int i=0;i<N;i++)
{
a[i+K] = a[i+N+K] = 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];
}
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] = -INF;
dp[i][1] = max(dp[i][1], dp[i-1][1]+a[i]-b[i]);
dp[i][1] = max(dp[i][1], dp[i-K][0]+a[i]-(prefb[i]-prefb[i-K]));
//cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<" dp\n";
}
return max(dp[N+K-1][0], dp[N+K-1][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/ccnPpOZi.o: in function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccOuPERk.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status