Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N = 1e6 + 6;
- int n, a[N];
- stack <int> st;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- while (scanf("%d", &n))
- {
- if (n == 0) break;
- long long res = 0;
- for (int i = 0; i < n; ++i)
- {
- scanf("%d", &a[i]);
- }
- int cur = 0;
- while (cur < n)
- {
- if (st.empty() || a[st.top()] <= a[cur])
- st.push(cur++);
- else
- {
- int tp = st.top();
- st.pop();
- res = max(res, 1LL * (0LL + a[tp]) * (st.empty() ? cur : cur - st.top() - 1));
- }
- }
- while (!st.empty())
- {
- int tp = st.top();
- st.pop();
- res = max(res, 1LL * (0LL + a[tp]) * (st.empty() ? cur : cur - st.top() - 1));
- }
- cout << res << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement