Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e6 + 6;
  4. int n, a[N];
  5. stack <int> st;
  6.  
  7. int main()
  8. {
  9.     ios::sync_with_stdio(0);
  10.     cin.tie(0);
  11.     while (scanf("%d", &n))
  12.     {
  13.         if (n == 0) break;
  14.         long long res = 0;
  15.         for (int i = 0; i < n; ++i)
  16.         {
  17.             scanf("%d", &a[i]);
  18.         }
  19.         int cur = 0;
  20.         while (cur < n)
  21.         {
  22.             if (st.empty() || a[st.top()] <= a[cur])
  23.                 st.push(cur++);
  24.             else
  25.             {
  26.                 int tp = st.top();
  27.                 st.pop();
  28.                 res = max(res, 1LL * (0LL + a[tp]) * (st.empty() ? cur : cur - st.top() - 1));
  29.             }
  30.         }
  31.         while (!st.empty())
  32.         {
  33.             int tp = st.top();
  34.             st.pop();
  35.             res = max(res, 1LL * (0LL + a[tp]) * (st.empty() ? cur : cur - st.top() - 1));
  36.         }
  37.         cout << res << '\n';
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement