-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1027C.cpp
More file actions
54 lines (49 loc) · 966 Bytes
/
1027C.cpp
File metadata and controls
54 lines (49 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
struct frac {
ll a,b;
frac(ll a_, ll b_) {
a=a_; b=b_;
}
};
int main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int t; cin>>t;
while(t--) {
int n; cin>>n;
map<int,int> ct;
int x;
for (int i=0; i<n; i++) cin>>x, ct[x]++;
bool up=false;
for (auto it : ct) {
if(it.second>=4) {
for (int i=0; i<4; i++) cout << it.first << " ";
cout << endl;
up=true;
break;
}
}
if(up) continue;
vector<int> cand;
for (auto it : ct)
if(it.second>=2)
cand.push_back(it.first);
int sz=cand.size();
frac mn=frac(1e9,1);
int idx=-1;
for (int i=0; i<sz-1; i++) {
int x=cand[i], y=cand[i+1];
int p=2*(x+y), s=x*y;
frac cur=frac(p*p,s);
if(mn.a*cur.b>cur.a*mn.b)
mn=cur, idx=i;
}
for (int i=0; i<2; i++)
for (int j=0; j<2; j++)
cout << cand[idx+i] << " ";
cout << endl;
}
return 0;
}