Array target sum triplets. Please find the error in this code. I did find a better code but I wanted to know what's wrong with my code

#include
#include
using namespace std;
int main()
{
int n,a[1000],i,target,j;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cin>>target;
sort( a , a + n);
for(i=0;i<n;i++)
{
for(j=i+1;j<n-1;)
{

	while (j<n-1)
	{

	if (a[i]+a[n-1]+a[j]==target)
	{
		cout<<a[i]<<", "<<a[j]<<" and "<<a[n-1]<<endl;
	}

  if(a[i]+a[n-1]+a[j]>target)
	{ n--; }
	else j++;

	
	}
	}
	

}


return 0;

}

plz share link of your code
save at ide.codingblocks.com and send the link