Samkit5025

Untitled

Aug 13th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int minimumTree(int n,vector<int> &a){
  5.  
  6.     queue<pair<int,int>> q;
  7.     q.push({1,0});
  8.     int idx = 1;
  9.     int ans = 0;
  10.     while(!q.empty()){
  11.         pair<int,int> temp = q.front();
  12.         q.pop();
  13.         int last = -1;
  14.         while(idx<n && a[idx]>last){
  15.             q.push({a[idx],temp.second+1});
  16.             ans = max(ans,temp.second+1);
  17.             last = a[idx];
  18.             idx++;
  19.         }
  20.     }
  21.     return ans;
  22. }
  23.  
  24. signed main() {
  25.     int n;
  26.     cin>>n;
  27.    
  28.     vector<int> a(n);
  29.     for(int i=0;i<n;i++){
  30.         cin>>a[i];
  31.     }
  32.  
  33.     cout<<minimumTree(n,a)<<endl;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment