Why is my solution being able to pass just a single test case? I can't understand where did I get it wrong.Could you please help

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

int main() {
int n;
cin>>n;
vectorv1(n),v2(n);
for(int i=0;i<n;i++){
cin>>v1[i]>>v2[i];
}
int begin=0,end=n;
while(begin<end){
int i1=(begin+end)/2;
int i2=(2*n+1)/2-i1;
int min1=(i1==n)?INT_MAX:v1[i1];
int max1=(i1==0)?INT_MIN:v1[i1-1];
int min2=(i2==n)?INT_MAX:v2[i2];
int max2=(i2==0)?INT_MIN:v2[i2-1];

	if(max1<=min2&&max2<=min1){
		cout<< (max(max1,max2)+min(min1,min2))/2;
		break;
	}
	else if(max1>min2)end=i1-1;
	else begin=i1+1;
}
return 0;

}

Hey @rai.tejas1998

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

int main() {
	int n;
	cin>>n;
	vector<int>v1(n),v2(n);
	for(int i=0;i<n;i++){
		cin>>v1[i]; //v1 here
	}
	for(int i=0;i<n;i++){
		cin>>v2[i];//v2 here
	}
	int begin=0,end=n;
	while(begin<end){
		int i1=(begin+end)/2;
		int i2=(2*n+1)/2-i1;
		int min1=(i1==n)?INT_MAX:v1[i1];
		int max1=(i1==0)?INT_MIN:v1[i1-1];
		int min2=(i2==n)?INT_MAX:v2[i2];
		int max2=(i2==0)?INT_MIN:v2[i2-1];

		if(max1<=min2&&max2<=min1){
			cout<< (max(max1,max2)+min(min1,min2))/2;
			break;
		}
		else if(max1>min2)end=i1-1;
		else begin=i1+1;
	}
	return 0;
}