Test Cases problem

When I try to execute a program the sample input case test
passed but not the test case
for example in the given code :
#include
#include
using namespace std;
int main()
{
int a[1000];
int n;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
int key;
cin>>key;
for (int i=0;i<n-1;i++){

int l=i+1;
int r=n-1;
int x=a[i];
while(l<r)
{
	int current_sum=a[l]+a[r];
	if (x+current_sum >key)
	{
		r--;
	}
	else if(x+current_sum<key)
	
	{
		l++;
	}
	else if(x+current_sum==key)
	{
		cout<<x<<","<<a[l]<<" and "<<a[r]<<endl;
		l++;
		r--;
	}
}

}
return 0;
}

Check the format of output given in the sample output.There is a space after comma which you have missed.If still test cases does not pass then save your code on ide.codingblocks.com and then share its link.

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.