#include
#include
#include
using namespace std;
int binSearch(vector a,int start, int end, int key, int para)
{
int return_index = -1;
int mid= 0;
while(start <= end)
{
mid = (start + end)/2;
if(a[mid] == key)
{
return_index = mid;
if(para == 0)
{
//move left
end = mid - 1;
}
else{
//move right
start = mid + 1;
}
}
else if(a[mid] < key)
start = mid + 1;
else
end = mid - 1;
}
return return_index;
}
int main() {
int n;
cin>>n;
vector <int> a(n);
for(int i = 0; i < n; i++)
cin>>a[i];
sort(a.begin(), a.end());
int key;
cin>>key;
int left = 0, right = 0;
for(int i = 0; i< n; i++)
{
left = binSearch(a, i, n -1, key - a[i], 0);
right = binSearch(a, i, n -1, key - a[i], 1);
if(left != -1 || right != -1)
{
for(int j = left; j <= right; j++)
cout<<a[i]<<" and "<<a[j]<<endl;
}
}
return 0;
}
this is my code which is able to pass all the test cases except the first may you suggest the corner case in which it is getting error