Target sum triplets

error: /bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe

code:
#include
#include
using namespace std;

bool compare(int a, int b){
return a<b;
}

int main() {

int n, target, a[100], currentSum, l, r;
cin>>n;

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

cin>>target;
sort(a, a+n, compare);

for(int i = 0; i<n; i++){
	l = i+1;
	r = n-1;
	while(l<r){
		int lrsum = a[l] + a[r];
		if(lrsum < (target - a[i]))
			l++;
    
		else if(lrsum > (target - a[i]))
			r--;

		else if(lrsum == (target - a[i])){
			cout<<a[i]<<", "<<a[l]<<" and "<<a[r]<<endl;
			r--;
			l++;
		}
}

}

return 0;

}

Hey @arjun.12narang
What is the issue I can see u got 100/100

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.