My code gives run error while submitting while it compiles successfully on cb ide

#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int,int>a,pair<int,int>b)
{
return (a.first-a.second)<(b.first-b.second);

}
int main()
{
int test;
cin>>test;
do
{
int n;
cin>>n;
vectorv;
vector<pair<int,int>> ans;
v.reserve(n);
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
v.push_back(temp);

	}
	int m;
	cin>>m;
	cin.get();
	auto it=v.begin();
	while(it!=v.end())
	{
		if(binary_search(v.begin(),v.end(),(m-(*it))))
		ans.push_back(make_pair(*it,m-(*it)));
		it++;
	}
	sort(ans.begin(),ans.end(),comp);
	auto j=ans.begin();
	cout<<"Deepak should buy roses whose prices are "<<(*j).first<< " and "<<(*j).second<<endl;
	
}while(test--);

}

@aayuushh please save your code on ide.codingblocks.com and share the code

@aayuushh how are you using the binary_search function when there is no guarantee if the vector is sorted or not? moreover your code is giving segmentation fault for sample test case as well.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.