-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy path1027C-MinimumValueRectangle.cpp
More file actions
38 lines (32 loc) · 1.08 KB
/
1027C-MinimumValueRectangle.cpp
File metadata and controls
38 lines (32 loc) · 1.08 KB
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
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
int main(){
long t; scanf("%ld", &t);
while(t--){
long n; scanf("%ld", &n);
std::map<long, long> cnt;
for(long p = 0; p < n; p++){long x; scanf("%ld", &x); ++cnt[x];}
std::vector<long> pairs, quads;
for(std::map<long, long>::iterator it = cnt.begin(); it != cnt.end(); it++){
if(it->second >= 4){quads.push_back(it->first);}
if(it->second >= 2){pairs.push_back(it->first);}
}
if(quads.size() > 0){
long side = quads[0];
printf("%ld %ld %ld %ld\n", side, side, side, side);
}
else{
sort(pairs.begin(), pairs.end());
double minr(1e9); long x, y;
for(long p = 1; p < pairs.size(); p++){
long a(pairs[p - 1]), b(pairs[p]);
double r = (1.0 * a + b) * (1.0 * a + b) / (1.0 * a * b);
if(r < minr){x = a; y = b; minr = r;}
}
printf("%ld %ld %ld %ld\n", x, x, y, y);
}
}
return 0;
}