Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6.  
  7. ll a[1000010];
  8.  
  9. int main()
  10.  
  11. {
  12.     int n;
  13.     cin >> n;
  14.    for(int i = 0; i < n; i++)
  15.     {
  16.       cin >> a[i];
  17.     }
  18.     vector<int> arr;
  19.     stack<int> s;
  20.     int cnt=0,cnt1=0;
  21.   for(int i = 1; i < n; i++)
  22.   {
  23.  
  24.  
  25.         while ( !s.empty() && a[s.top()] >    a[i]  )
  26.         {
  27.             cnt++;
  28.             s.pop();
  29.         }
  30.     if ( !s.empty())
  31.     cnt=s.top();
  32.     s.push(i);
  33.     arr.push_back((i-cnt)*a[i]);
  34.     cnt=0;
  35.  
  36.   }
  37.  
  38.   int ans=0;
  39.   for ( int i =0;i<arr.size();i++)
  40.   {
  41.       ans=max(ans,arr[i]);
  42.   }
  43.   cout << ans;
  44.  
  45.   return 0;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement