Array-Target sum triplets solution not working HELP

I tried to build an O(n) solution which is passing the given test case but is failing at the hidden test cases.Can anyone please tell me whats wrong with my solution?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
int s;
cin>>s;
int i=1;
int start=1;
int j=n-1;
int end=n-1;
int cursum=0;
int k=0;
while(k<n/2-2)
{
cursum=a[i]+a[j]+a[k];
if(cursum>s)
j–;
else if(cursum<s)
i++;
else if(cursum==s)
{
cout<<a[k]<<", “<<a[i]<<” and "<<a[j]<<endl;
i++;
j–;
}
if(i>=j)
{
k++;
i=start+1;
j=end-1;
}

}

}