Advertisement
MathQ_

Untitled

Jun 22nd, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     vector<int> a(n);
  9.     for (auto &el : a) cin >> el;
  10.     a.push_back(0); ++n;
  11.  
  12.     long long ans = 1, pref = 1, suff = 1, all = 1;
  13.     int cntu = 0, st = -1, en = -1;
  14.     for (int i = 0; i < n; ++i) {
  15.         if (a[i] == 0) {
  16.             if (cntu % 2 == 0) {
  17.                 ans = max(ans, all);
  18.             } else {
  19.                 ans = max(ans, max(all / pref, all / suff));
  20.             }
  21.             pref = suff = all = 1;
  22.             continue;
  23.         }
  24.         if (a[i] < 0) {
  25.             ++cntu;
  26.             if (st == -1) { st = i; pref *= abs(a[i]); }
  27.             en = i;
  28.             suff = abs(a[i]);
  29.         }
  30.         all *= abs(a[i]);
  31.         if (st == -1) pref *= a[i];
  32.         suff *= a[i];
  33.     }
  34.     cout << ans << '\n';
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement