//this is my solution for the target sum triplet problem. It is not able to pass all the test cases. Why??
#include
#include
using namespace std;
int main() {
int n; cin>>n;
int arr[n];
for(int i=0; i<n; i++)
[[]] cin>>arr[i];
int key; cin>>key;
sort(arr, arr+n);
for(int i=0; i<n-2; i++)
{
int a=i+1;
int b=n-1;
while(a<b)
{
if((arr[i]+arr[a]+arr[b])>key)
b--;
if((arr[i]+arr[a]+arr[b])<key)
a++;
if(arr[i]+(arr[a]+arr[b])==key)
{
cout<<arr[i]<<", "<<arr[a]<<" and "<<arr[b]<<endl;
a++; b--;
}
}
}
return 0;
}