## L2-045 堆宝塔
题目链接：
https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1649748772841508872&page=1

题目分析：本题就是栈的模拟，用两个栈模拟基座就好了。**注意题目的描述，A柱上的彩虹圈从底到上时是逐次减小的，但是B柱上的彩虹圈从底到上是逐次变大的**
具体看代码吧！

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    queue<int> arr;
    for(int i=0;i<n;i++){
        int x;
        cin>>x; arr.push(x);
    }
    stack<int> sta;
    stack<int> stb;
    sta.push(arr.front());
    arr.pop();
    int total=0;
    int max_length=0;
    while(!arr.empty()){
        int topa=sta.top();
        int num=arr.front();
        arr.pop();
        if(num<topa){
            sta.push(num);
        }
        else{
            if(stb.empty() || (!stb.empty() && (stb.top()<num))){
                stb.push(num);
            }
            else{
                int a=sta.size();
                max_length=max(max_length,a);
                while(!sta.empty()){
                    sta.pop();
                }
                total++;
                while(!stb.empty() && stb.top()>num){
                    sta.push(stb.top());
                    stb.pop();
                }
                sta.push(num);
            }
        }
    }
    if(!sta.empty()){
        int a=sta.size();
        //max必须是一样的类型，否则会报错，可以用强制转换
        max_length=max(max_length,a);
        while(!sta.empty()){
        sta.pop();
        }
        total++;
    }
    if(!stb.empty()){
        int b=stb.size();
        max_length=max(max_length,b);
        while(!stb.empty()){
        stb.pop();
        }
        total++;
    }
    
    cout<<total<<" "<<max_length;
    return 0;
}

