Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll a[1000010];
- int main()
- {
- int n;
- cin >> n;
- for(int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- vector<int> arr;
- stack<int> s;
- int cnt=0,cnt1=0;
- for(int i = 1; i < n; i++)
- {
- while ( !s.empty() && a[s.top()] > a[i] )
- {
- cnt++;
- s.pop();
- }
- if ( !s.empty())
- cnt=s.top();
- s.push(i);
- arr.push_back((i-cnt)*a[i]);
- cnt=0;
- }
- int ans=0;
- for ( int i =0;i<arr.size();i++)
- {
- ans=max(ans,arr[i]);
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement