fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define LL long long
  6. #define DD double
  7. #define mem(a, b) memset(a, b, sizeof(a))
  8. #define fast ios_base::sync_with_stdio(0);cin.tie(0)
  9.  
  10. const int mx1 = 15;
  11. const int mx2 = 105;
  12. const int mx3 = 1005;
  13. const int mx4 = 10005;
  14. const int mx5 = 100005;
  15. const int mx6 = 1000005;
  16. const LL inf = 1e18;
  17. const DD EPSILON = 1e-10;
  18.  
  19. LL _toggle(LL N, int pos) {return N = N ^ (1ll << pos);}
  20. LL _set(LL N, int pos) {return N = N | (1ll << pos);}
  21. LL _reset(LL N, int pos) {return N = N & ~(1ll << pos);}
  22. LL _set_bit(LL N, int pos, bool B){if(B){N |= (1LL << pos);}else{N &= ~(1LL << pos);}return N;}
  23. bool _get(LL N, int pos) {return (bool)(N & (1ll << pos));}
  24. bool _upper(char a) {return a >= 'A' && a <= 'Z';}
  25. bool _lower(char a) {return a >= 'a' && a <= 'z';}
  26. bool _digit(char a) {return a >= '0' && a <= '9';}
  27. DD _fmax(DD a, DD b) {if(fabs(a - b) < EPSILON) return a; return (a > b) ? a : b;}
  28. DD _fmin(DD a, DD b) {if(fabs(a - b) < EPSILON) return a; return (a < b) ? a : b;}
  29. bool _less(DD a, DD b) {if(fabs(a - b) < EPSILON) return false; return a < b;}
  30. bool _eql(DD a, DD b) {if(fabs(a - b) < EPSILON) return true; return a == b;}
  31.  
  32. int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
  33. int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
  34.  
  35. ///******************************************************///
  36. /*
  37. g++-14 C.cpp -o C
  38. */
  39.  
  40. bool F(LL X, LL Y, LL x, LL y)
  41. {
  42. LL gcd1 = __gcd(X, Y), gcd2 = __gcd(x, y);
  43. X /= gcd1, Y /= gcd1;
  44. x /= gcd1, y /= gcd1;
  45. LL lcm = Y * y / __gcd(Y, y);
  46. X *= lcm / Y, x *= lcm / y;
  47. return X < x;
  48. }
  49.  
  50. void clearAll()
  51. {
  52.  
  53. }
  54.  
  55. void solve()
  56. {
  57. LL n;
  58. cin >> n;
  59. map<LL, LL> mp;
  60. for(LL i = 0; i < n; i++){
  61. LL u;
  62. cin >> u;
  63. mp[u]++;
  64. }
  65. vector<LL> a;
  66. for(auto i: mp){
  67. if(i.second >= 4){
  68. LL cnt = 4;
  69. while(cnt--){
  70. cout << i.first << ' ';
  71. }
  72. cout << '\n';
  73. return;
  74. }
  75. if(i.second > 1){
  76. a.push_back(i.first);
  77. }
  78. }
  79. LL top = -1, bot = -1, ansId = -1;
  80. for(LL i = 1; i < a.size(); i++){
  81. LL curTop = 4 * (a[i] + a[i - 1]) * (a[i] + a[i - 1]);
  82. LL curBot = a[i] * a[i - 1];
  83. if(i == 1 || F(curTop, curBot, top, bot)){
  84. top = curTop, bot = curBot;
  85. ansId = i;
  86. }
  87. }
  88. cout << a[ansId] << ' ' << a[ansId] << ' ' << a[ansId - 1] << ' ' << a[ansId - 1] << '\n';
  89. }
  90.  
  91. void precalculation()
  92. {
  93.  
  94. }
  95.  
  96. int main()
  97. {
  98. //freopen("input.txt", "r", stdin);
  99. //freopen("output.txt", "w", stdout);
  100. fast;
  101. precalculation();
  102. int TC = 1;
  103. cin >> TC;
  104. while(TC--){
  105. solve();
  106. }
  107. }
  108.  
  109.  
Success #stdin #stdout 0.01s 5288KB
stdin
3
4
7 2 2 7
8
2 8 1 4 8 2 1 5
5
5 5 5 5 5
stdout
7 7 2 2
2 2 1 1
5 5 5 5