Advertisement
a53

Hill Climb

a53
Nov 19th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. using namespace std;
  5.  
  6. const int NMAX = 1e5;
  7. const int INF = 2e9;
  8.  
  9. int N;
  10. int a[NMAX + 2];
  11.  
  12. void Test() {
  13. cin >> N;
  14.  
  15. a[0] = INF;
  16. for(int i = 1; i <= N; i++)
  17. cin >> a[i];
  18.  
  19. stack <int> st;
  20. st.push(0);
  21.  
  22. int l = 0;
  23. for(int i = 1; i <= N; i++) {
  24. while(!st.empty() && a[st.top()] < a[i])
  25. st.pop();
  26.  
  27. l = max(l, i - st.top() - 1);
  28. st.push(i);
  29. }
  30.  
  31. cout << l << '\n';
  32. }
  33.  
  34. int main()
  35. {
  36. ios_base::sync_with_stdio(false);
  37. cin.tie(0);
  38.  
  39. int t; cin >> t;
  40. while(t--) Test();
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement