Solution Not passing all the test cases.
#include
#include
using namespace std;
int main() {
int i,j,k,t=0,n;
int l,r;
int a[1000];
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cin>>t;
sort(a,a+n);
for(i=0;i<n;i++)
{
l=i+1;
r=n-1;
while(l<r)
{
if(t==(a[i]+a[l]+a[r]))
{
cout<<a[i]<<", “<<a[l]<<” and "<<a[r]<<endl;
l++;
r–;
}
else if((a[i]+a[l]+a[r])>t)
{
r–;
}
else{
l++;
}
}
}
return 0;
}