A-scx 的散文诗句_华中农业大学第十三届程序设计竞赛(同步赛) (nowcoder.com)
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+6;
const int inf=0x3f3f3f3f;
int a[N];
void solve()
{int n;cin>>n;int nct=0;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+1+n);for(int l=1,r=n;l<r;){int fk1=a[l]*a[l+1];int fk2=a[r]*a[r-1];if(fk1<fk2){nct+=fk2;r-=2;}else{nct+=fk1;l+=2;}}cout<<nct<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;cin>>t;while(t--){solve();}return 0;
}