#include
#include
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int key;
cin>>key;
sort(arr,arr+n);
int i=0;int j=n-1;
while(i<j)
{
if(arr[i]+arr[j]==key)
{
cout<<arr[i]<<" and "<<arr[j]<<endl;
i++;j++;
}
if(arr[i]+arr[j]>key)
{
j–;
}
else{
i++;
}
}
return 0;
}
test case 2 is note working why???
code is similar to solution.