Correct answers are not passing the test cases!

"#include<bits/stdc++.h>
using namespace std;

int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}

sort(arr,arr+n);

int target;
cin>>target;

for(int i=0;i<n;i++)
{
    for(int j=i+1;j<n;j++){
        for(int k=j+1;k<n;k++){
            if(arr[i]+arr[j]+arr[k] == target)
                cout<<arr[i]<<","<<arr[j]<<" and "<<arr[k]<<"\n";
        }
    }
}

}"

The above is my code for the Arrays-Target Sum Triplets. It was not passing the private the test cases but when I opened the editorial it is showing the same code. What is the error??? Please look into it.

@jamesallenvinoy hey james your loops is not right
the loop should be like
for(int i=0;i<n-2;i++)
for(int j=i+1;j<n-1;j++)
for(int k=j+1;k<n;k++)