fork download
  1. /* Authors: Vu Hoang Bach from Phuoc Hoa Secondary School */
  2.  
  3. //#pragma GCC optimize("O3", "unroll-loops")
  4. //#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
  5.  
  6. #include <bits/stdc++.h>
  7. #define ldb long double
  8. //#define double ldb
  9. #define db double
  10. #define unomap unordered_map
  11. #define unoset unordered_set
  12. #define endl '\n'
  13. #define str string
  14. #define strstr stringstream
  15. #define sz(a) (int)a.size()
  16. #define ll long long
  17. //#define int ll
  18. #define pii pair <int, int>
  19. #define pll pair <ll, ll>
  20. #define Unique(a) a.resize(unique(all(a)) - a.begin())
  21. #define ull unsigned ll
  22. #define fir first
  23. #define sec second
  24. #define idc cin.ignore()
  25. #define lb lower_bound
  26. #define ub upper_bound
  27. #define all(s) s.begin(), s.end()
  28. #define rev reverse
  29. #define sigma ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  30. #define skibidi int main
  31. #define rizz signed main
  32. #define gcd __gcd
  33. #define found(a, mp) mp.find(a) != mp.end()
  34. #define pushb push_back
  35. #define popb pop_back
  36. #define pushf push_front
  37. #define popf pop_front
  38. #define mul2x(a, x) a << x
  39. #define div2x(a, x) a >> x
  40. #define lcm(a, b) (a / __gcd(a, b) * b)
  41. #define log_base(x, base) log(x) / log(base)
  42. #define debug clog << "No errors!"; exit(0);
  43. #define forw(i, a, b) for (int i = a; i <= b; ++i)
  44. #define forw2(i, a, b) for (ll i = a; i <= b; ++i)
  45. #define fors(i, a, b) for (int i = a; i >= b; --i)
  46. #define fors2(i, a, b) for (ll i = a; i >= b; --i)
  47. #define pqueue priority_queue
  48. #define sqrt sqrtl
  49. #define want_digit(x) cout << fixed << setprecision(x);
  50. #define excuting_time 1000.0 * clock() / CLOCKS_PER_SEC
  51. using namespace std;
  52. const int MOD = 1e9 + 7; // 998244353
  53. const int inf = 1e9;
  54. const ll INF = 1e18;
  55. const int N = 1e5;
  56.  
  57. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  58. ll random(const ll &L, const ll &R)
  59. {
  60. return uniform_int_distribution<ll> (L, R) (rng);
  61. }
  62.  
  63. int n, l, r;
  64. ll a[N + 5], ans;
  65.  
  66. void recur(int l, int r, int chosen, ll sum)
  67. {
  68. if (chosen == 3)
  69. {
  70. ans = max(ans, sum);
  71. return;
  72. }
  73.  
  74. forw (i, 0, 3)
  75. {
  76. ll add = 1;
  77. int lef = i, rig = 3 - i;
  78. forw (j, l, l + lef - 1) add *= a[j];
  79. forw (j, r - rig + 1, r) add *= a[j];
  80.  
  81. recur(l + lef, r - rig, chosen + 1, sum + add);
  82. }
  83. }
  84.  
  85. void cook()
  86. {
  87. cin >> n;
  88. forw (i, 1, n) cin >> a[i];
  89. sort(a + 1, a + n + 1);
  90.  
  91. ans = -INF;
  92. recur(1, n, 0, 0);
  93. cout << ans << endl;
  94. }
  95.  
  96. skibidi()
  97. //rizz()
  98. {
  99. srand(time(NULL));
  100. sigma;
  101. #define name "test"
  102. /*
  103.   if (fopen(name".INP", "r"))
  104.   {
  105.   freopen(name".INP", "r", stdin);
  106.   freopen(name".OUT", "w", stdout);
  107.   }
  108.   */
  109. int numTest = 1;
  110. // cin >> numTest;
  111. while (numTest--)
  112. {
  113. cook();
  114. }
  115. return 0;
  116. }
  117.  
Success #stdin #stdout 0s 5320KB
stdin
10
0 2 2 0 2 -1 1 -1 0 0
stdout
9