Two pointer approach

HI I am getting TLE while using two pointer approach .
Pasting my code below what issue does it have

#include
#include
using namespace std;

int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int k;
cin>>k;
sort(a,a+n);
int l = 0;
int r = n-1;
while(l<r){
int s = (a[l]+a[r]);
if(s==k){
cout<<a[l]<<" and "<<a[r]<<endl;
}
else if(s>k){
r–;
}
else if(s<k){
l++;
}
}

return 0;

}

@Prateekkewale you submission shows 100 so i think your doubt is resolved now.
just mark it resolved

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.