Advertisement
Dang_Quan_10_Tin

MMAX TS10 Da Nang 2021-2022

Jan 6th, 2022
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #define task "MMAX"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. constexpr int N = 1e5 + 5;
  13. int n, a[N];
  14.  
  15. void Read()
  16. {
  17.     cin >> n;
  18.  
  19.     for (int i = 1; i <= n; ++i)
  20.         cin >> a[i];
  21. }
  22.  
  23. ll Haiso()
  24. {
  25.     return max(1ll * a[1] * a[2], 1ll * a[n - 1] * a[n]);
  26. }
  27.  
  28. ll Baso()
  29. {
  30.     return max(1ll * a[n] * a[n - 1] * a[n - 2], 1ll * a[1] * a[2] * a[n]);
  31. }
  32.  
  33. void Solve()
  34. {
  35.     sort(a + 1, a + n + 1);
  36.  
  37.     cout << max(Haiso(), Baso());
  38. }
  39.  
  40. int32_t main()
  41. {
  42.     ios::sync_with_stdio(0);
  43.     cin.tie(0);
  44.     cout.tie(0);
  45.     if (fopen(task ".INP", "r"))
  46.     {
  47.         freopen(task ".INP", "r", stdin);
  48.         freopen(task ".OUT", "w", stdout);
  49.     }
  50.  
  51.     Read();
  52.     Solve();
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement