Wrong ANswer upon Submission for PAIRSUM. can anyone help please. works fine for test cases

#include
#include
#include
#include

using namespace std;

int main(){
int i,j,n,x[100],val,max=0,cur,l,r;
scanf("%d",&n);
for(i=0;i<=n-1;i++)
	scanf("%d",x+i);
sort(&x[0],&x[n]);
set<int> s;
for(i=0;i<=n-1;i++){
	for(j=i+1;j<=n-1;j++){
		s.insert(x[i]+x[j]);
	}
}
set<int>::iterator it;
for(it=s.begin();it!=s.end();it++){
	val = *it;
	l = 0;
	r = n-1;
	cur = 0;
	while(l < r){
		if (x[l]+x[r] > val)
			r--;
		if (x[l]+x[r] < val)
			l++;
		if (x[l]+x[r] == val){
			cur++;
			l++;
			r--;
		}
	}
	if(cur > max)
		max = cur;
}
printf("%d\n", 2*max);
return 0;
}

got the solution. it was the array going out of bound. Codechef specifications told that array size max is 100 but it appears array can go outside that…