Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int minimumTree(int n,vector<int> &a){
- queue<pair<int,int>> q;
- q.push({1,0});
- int idx = 1;
- int ans = 0;
- while(!q.empty()){
- pair<int,int> temp = q.front();
- q.pop();
- int last = -1;
- while(idx<n && a[idx]>last){
- q.push({a[idx],temp.second+1});
- ans = max(ans,temp.second+1);
- last = a[idx];
- idx++;
- }
- }
- return ans;
- }
- signed main() {
- int n;
- cin>>n;
- vector<int> a(n);
- for(int i=0;i<n;i++){
- cin>>a[i];
- }
- cout<<minimumTree(n,a)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment