Why my code is not working?

#include
#include<bits/stdc++.h>
using namespace std;

int solve(vector arr,int n,int k){
int dpf[n]={0};
if(k+1<n) dpf[k+1]=arr[k+1];
if(k+2<n) dpf[k+2]=arr[k+2];
for(int i=k+3;k<n;k++){
dpf[i]=arr[i]+max(dpf[i-2],dpf[i-1]);
}

int dpb[n]={0};
dpb[1]=arr[1];
dpb[2]=arr[2]+arr[1];
for(int i=3;i<n;i++){
	dpb[i]=arr[i]+max(dpb[i-1],dpb[i-2]);
}

for(int i=0;i<n;i++){
	cout << dpf[i] << " ";
}
cout << endl;

for(int i=0;i<n;i++){
	cout << dpb[i] << " ";
}

int ans=0;
for(int i=1;i<n;i++){
	ans=max(ans,dpf[i]+dpb[i]-arr[i]);
}
return ans;

}

int main () {
int n,k;
cin >> n,k;

vector<int> arr(n+1);
for(int i=1;i<=n;i++){
	cin >> arr[i];
}

cout << solve(arr,n+1,k);

return 0;

}