#ifndef __HOMECOMING_H
#define __HOMECOMING_H
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000000000
#define umax(x,y) x=max(x,y)
ll psum[2000005],psum2[2000005];
long long solve(int N, int K, int *A, int *B) {
vector< vector<ll> > dp[2];
for(int i=0;i<2;i++) {
dp[i].resize(N+2);
for(int j=0;j<N+2;j++) {
dp[i][j].resize(K+1);
}
}
for(int i=N;i>=1;i--) {
A[i]=A[i-1];
B[i]=B[i-1];
}
for(int i=1;i<=N;i++) psum[i]=psum[i-1]+B[i],psum2[i]=psum2[i-1]+A[i];
for(int i=1;i<=N;i++) for(int j=0;j<=min(i-1,K);j++) for(int t=0;t<2;t++) dp[t][i][j]=-inf;
dp[1][1][0]=0;
for(int i=1;i<=N;i++) {
for(int j=0;j<=min(i-1,K);j++) {
umax(dp[1][i+1][j+(j==i-1)],dp[1][i][j]-B[i]+(i+1-K+1>=1?A[i+1-K+1]:0));
umax(dp[0][i+1][j],dp[1][i][j]);
if(i+K<=N+1) {
umax(dp[1][i+K][j],dp[0][i][j]+A[i]-(psum[i+K-1]-psum[i-1]));
}
else {
int amount=min(N+1-i,j+N+1-i-K+1);
umax(dp[1][K+1][j],dp[0][i][j]+psum2[i+amount-1]-psum2[i-1]);
}
umax(dp[0][i+1][j],dp[0][i][j]);
}
}
ll res=0;
for(int i=0;i<=min(N-1,K);i++) umax(res,max(dp[0][N+1][i],dp[1][N+1][i]));
return res;
}
int main() {
freopen("in.txt","r",stdin);
int T; assert(scanf("%d", &T) == 1);
for(int t = 0; t < T; t++) {
int N, K; assert(scanf("%d%d", &N, &K) == 2);
int *A = new int[N];
int *B = new int[N];
for(int i = 0; i < N; i++) assert(scanf("%d", &A[i]) == 1);
for(int i = 0; i < N; i++) assert(scanf("%d", &B[i]) == 1);
printf("%lld\n", solve(N, K, A, B));
delete[] A;
delete[] B;
}
return 0;
}
#endif
Compilation message
homecoming.cpp: In function 'int main()':
homecoming.cpp:75:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("in.txt","r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~
/tmp/ccPbzWeL.o: In function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccHNKefT.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status