Why segmentation fault?

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

int solve(vector arr,int i,int sum,int n){
if(i==1) return sum;

int op1=0,op2=0,op3=0,op4=0;
if((i+1)<n) op1=solve(arr,i+1,sum+arr[i+1],n);
if((i+2)<n) op2=solve(arr,i+2,sum+arr[i+2],n);
if((i-1)>0) op3=solve(arr,i-1,sum+arr[i-1],n);
if((i-2)>0) op4=solve(arr,i-2,sum+arr[i-2],n);

return max(max(op1,op2),max(op3,op4));

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

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

cout << solve(arr,k,0,n);
return 0;

}