解析:
当任意一个数都+1,这个数都会变成最大值时为sum-max-min
否则都为 sum-max-min+1
只需要排序后,从第二个到最后都相等时不成立
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,a[N];
void solve(){
scanf("%lld",&n);
int sum=0,maxx=0,minn=0x3f3f3f3f;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum+=a[i];
maxx=max(maxx,a[i]);
minn=min(minn,a[i]);
}
sort(a+1,a+n+1);
int p=a[2];
for(int i=3;i<=n;i++){
if(a[i]!=p){
printf("%lld\n",sum-maxx-minn+1);
return;
}
}
printf("%lld\n",sum-maxx-minn);
}
signed main(){
int t=1;
scanf("%lld",&t);
while(t--) solve();
return 0;
}