ivyjiao
2024-11-19 07:16:59
水题,十分钟切了。
很明显我们需要找到
然后我们想到:
设第
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1;
unordered_map<int,int>mp;
int t,n,a[N];
vector<int>b;
int main(){
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]++;
}
for(int i=1;i<=n;i++){
if(mp[a[i]]>1){
mp[a[i]]-=2;
b.push_back(a[i]);
}
}
sort(b.begin(),b.end());
if(b.size()<4) cout<<"NO"<<endl;
else{
cout<<"YES"<<endl;
cout<<b[0]<<" "<<b[1]<<" "<<b[0]<<" "<<b[b.size()-1]<<" "<<b[b.size()-2]<<" "<<b[1]<<" "<<b[b.size()-2]<<" "<<b[b.size()-1]<<endl;
}
b.clear();
mp.clear();
}
}