Not able to deal with TLE , sir here i have used two pointer method and i dont know why is it taking that much time, a hint would help!

#include
#include
using namespace std;
void findnum(int arr[], int m, int k)
{
int i=0,j=m-1;
while(i<j)
{
if(arr[i]+arr[j]<k)
{++i;}
if(arr[i]+arr[j]>k)
{ --j;}
if(arr[i]+arr[j]==k)
{ cout<<arr[i]<<" and "<<arr[j];}
}
}
int main() {
int n,target;
cin>>n;
int *a = new int[n];
for(int i=0;i<n;++i)
{
cin>>a[i];
}
cin>>target;
sort(a,a+n);
findnum(a,n,target);
delete[]a;
return 0;
}

Now it’s working https://ide.codingblocks.com/s/330818

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.