Only passing 1 of 5 test cases

#include
#include
using namespace std;
void tst(int a[],int n,int key)
{
int i,j,k;
sort(a,a+n);
for(i=0;i<n-2;i++)
{
j=i+1;
k=n-1;
while(j<k&&k>i)
{
if(a[i]+a[j]+a[k]>key)
k–;
if(a[i]+a[j]+a[k]<key)
j++;
if(a[i]+a[j]+a[k]==key)
{
cout<<a[i]<<","<<" β€œ<<a[j]<<” β€œ<<β€œand”<<” "<<a[k]<<endl;
}
}
}
}
int main() {
int i,n,key;
cin>>n;
int a[1000];
for(i=0;i<n;i++)
cin>>a[i];
cin>>key;
tst(a,n,key);
return 0;
}

@tushartiwari
hello tushar,

use if, else-if and else in place of three if

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.