Advertisement
leminhkt

noname15 (KPLANK)

Mar 3rd, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define FORn(i, n) for(int i=1; i<=(n); i++)
  3. #define FORRn(i, n) for(int i=(n); i>=1; i--)
  4. using namespace std;
  5.  
  6. int n, res;
  7. deque<int> s;
  8. int main(){
  9.     cin>>n;
  10.     vector<int> h(n+2, 0), l(n+2, 0), r(n+2, 0);
  11.     s.push_back(0);
  12.     FORn(i, n){
  13.         cin>>h[i];
  14.         while(h[i]<=h[s.back()]) s.pop_back();
  15.         l[i]=s.back();
  16.         s.push_back(i);
  17.     }
  18.     s={n+1};
  19.     FORRn(i, n){
  20.         while(h[i]<=h[s.front()]) s.pop_front();
  21.         r[i]=s.front();
  22.         s.push_front(i);
  23.     }
  24.     FORn(i, n){
  25.         if(h[i]<=res) continue;
  26.         if(r[i]-l[i]-1>=h[i]) res=h[i];
  27.     }
  28.     cout<<res;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement