Median of 2 sorted arrays

#include
using namespace std;
#include
#include
#include
int main(){
int n; vector a(n); vector b(n);
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
//merge sort of the two arrys
int i=0,j=0,count=0;
while(i<n && j<n){
if(a[i]<b[i]) i++;
else j++;
count++;
if(count==n) break;
}
cout<<(a[i]+b[j])/2;
return 0;
}
Even this is returning segmentation fault. please explain.