Target sum triplet

code not working
2 test cases are not being fulfilled

hey, can you send me your code so i can help

#include
#include
using namespace std;
bool compare(int a,int b)
{
return a<b;
}
int main()
{
int n;
cin>>n;
int a[1000];
int s;
for(s=0;s<n;s++)
{
cin>>a[s];
}
int target;
cin>>target;
int l;
int i;
int r;
int cs=0;
for(i=0;i<n-2;i++)
{
l=i+1;
r=n-1;
while(l<r)
{
cs=a[i]+a[l]+a[r];
if(cs>target)
{
r–;
}
else if(cs<target)
{
l++;
}
else if(cs==target)
{
cout<<a[i]<<", “<<a[l]<<” and "<<a[r];
l++;
r–;
}
}
}
}
here is my code

hey, it is tough to understand the unindented code, i will explain u the approach
step 1: sort the array
step 2: run a for loop for i=0 : n
step 3: skip duplicates
step 4: take k at n-1 and j = i+1; iterate for these elements now
step 5: skip duplicates of a[j] and a[k[
step 6; check sum of a[i] a[j[ and a[k]
here is the code
vector output;
sort(nums.begin(), nums.end());
for (int i = 0; i < nums.size(); ++i) {
// Never let i refer to the same value twice to avoid duplicates.
if (i != 0 && nums[i] == nums[i - 1]) continue;
int j = i + 1;
int k = nums.size() - 1;
while (j < k) {
if (nums[i] + nums[j] + nums[k] == 0) {
output.push_back({nums[i], nums[j], nums[k]});
++j;
// Never let j refer to the same value twice (in an output) to avoid duplicates
while (j < k && nums[j] == nums[j-1]) ++j;
} else if (nums[i] + nums[j] + nums[k] < 0) {
++j;
} else {
–k;
}
}
}
return output;
}
use this function to refer to the correct code

hey @Vipul.kapoor if your doubt is solved, please mark it as resolved