#include<iostream>
#include<vector>
#include "homecoming.h"
#define int long long
using namespace std;
const int N=2e6+2;
const int inf=1e18+2;
int dp[N][2][2],sum[N],sum1[N]; //co chon khong , loai nao
long long solve(int n,int k,vector<int> A,vector<int> B){
int i,j;
for(i=0;i<B.size();i++){
sum[i]=B[i];
if(i){
sum[i]+=sum[i-1];
}
dp[i][0][0]=-inf;
dp[i][1][0]=-inf;
dp[i][0][1]=-inf;
dp[i][1][1]=-inf;
}
dp[0][0][0]=0;
dp[0][1][1]=A[0]-sum[k-1];
// cout<<dp[0][1][1]<<endl;
for(i=1;i<n;i++){
dp[i][0][0]=max(dp[i-1][0][0],dp[i-1][1][0]);
dp[i][0][1]=max(dp[i-1][0][1],dp[i-1][1][1]);
if(i+k-1<n){
dp[i][1][0]=min(dp[i-1][1][0]+A[i]-B[i+k-1],dp[i-1][0][0]+A[i]-(sum[i+k-1]-sum[i-1]));
dp[i][1][1]=max(dp[i-1][1][1]+A[i]-B[i+k-1],dp[i-1][0][1]+A[i]-sum[i+k-1]+sum[i-1]);
}
else{
dp[i][1][0]=min(dp[i-1][1][0]+A[i]-B[i+k-1-n],dp[i-1][0][0]+A[i]-sum[i+k-1-n]-sum[n-1]+sum[i-1]);
dp[i][1][1]=max(dp[i-1][1][1]+A[i],dp[i-1][0][1]+A[i]-sum[n-1]+sum[i-1]);
}
//cout<<dp[i][1][1]<<endl;
}
//cout<<dp[n-1][1][1]<<endl;
return max(max(dp[n-1][0][1],dp[n-1][1][0]),max(dp[n-1][1][1],dp[n-1][0][1]));
}
signed main(){
cout<<solve(3,2,{40,80,100},{140,0,20});
}
Compilation message
homecoming.cpp: In function 'long long int solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>)':
homecoming.cpp:11:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<B.size();i++){
~^~~~~~~~~
homecoming.cpp:10:8: warning: unused variable 'j' [-Wunused-variable]
int i,j;
^
/tmp/ccPBl551.o: In function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cctYsVqg.o:grader.cpp:(.text.startup+0x0): first defined here
/tmp/cctYsVqg.o: In function `main':
grader.cpp:(.text.startup+0xff): undefined reference to `solve(int, int, int*, int*)'
collect2: error: ld returned 1 exit status