My code is not passing the last test case. Please help
#include<bits/stdc++.h>
using namespace std;
void target_sum(int a[], int n, int target)
{
int left = 0;
int right = n-1;
bool sum_found = false;
while(left<=right)
{
int sum = a[right]+a[left];
if(sum<target)
{
left++;
}
else if(sum>target)
{
right--;
}
else
{
cout<<a[left]<<" and "<<a[right]<< endl;
left++;
right--;
sum_found= true;
}
}
if(!sum_found)
{
cout<<"Sum is not found";
}
}
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int x;
cin>>x;
sort(arr,arr+n);
target_sum(arr,n,x);
}