题解 | #大雨吃小鱼#
大雨吃小鱼
https://www.nowcoder.com/practice/77199defc4b74b24b8ebf6244e1793de
#include <iostream> #include <utility> #include <vector> #include <stack> using namespace std; int main() { int m; cin>>m; vector<int> fash(m, 0); for(int i=0; i<m; i++) { cin>>fash[i]; } stack<pair<int, int>> s; pair<int, int> tops; int res=0; for(int i=m-1;i>=0; i--) { int counts = 0; while(!s.empty() && fash[i] > s.top().first) { tops = s.top(); s.pop(); counts = max(counts+1, tops.second); } s.push({fash[i], counts}); res = max(res, counts); } cout<<res<<endl; return 0; }