The below code is getting TLE error i.e Time limit Exceeded Error. I am finding it difficult to solve it without using nested for loops.Can someone tell a faster logic or can improve this code.
#include <stdio.h>
int mean(int arr[],int n,int b){
int m,s=0;
for(int i=0;i<n;i++){
s=arr[i]+s;
}
m=s/b;
return m;
}
int main(void) {
int t;
scanf("%d",&t);
while(t){
int n;
scanf("%d",&n);
int arr[n];
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
int x,c=0;
int m=mean(arr,n,n);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
int a=arr[i];
int b=arr[j];
arr[i]=0;
arr[j]=0;
x=mean(arr,n,n-2);
if(x==m)
c++;
arr[i]=a;
arr[j]=b;
}
}
printf("%d\n",c);
t--;
}
return 0;
}