#include<iostream>
#include<algorithm>
using namespace std;
int t;
int main(){
cin >> t;
while(t--){
int n,time[1005],cnt = 0;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> time[i];
}
sort(time+1,time+1+n);
while(n >= 4){
cnt += min(time[2]+time[1]+time[n]+time[2],time[n]+time[1]+time[n-1]+time[1]);
n-=2;
}
if(n == 3){
cnt += time[2]+time[1]+time[3];
}else if(n == 2){
cnt += time[2];
}else{
cnt += time[1];
}
cout << cnt << endl;
}
return 0;
}
Crossing River
最新推荐文章于 2024-10-07 19:01:55 发布