Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <stack>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i =0; i < n; i++) {
- cin >> v[i];
- }
- stack<pair<int, int> > st;
- int result = 0;
- for(int i =0 ; i < n; i++) {
- int day = 0;
- while(!st.empty() and st.top().first >= v[i]) {
- day = max(day, st.top().second);
- st.pop();
- }
- if(!st.empty()) {
- ++day;
- }
- else {
- day = 0;
- }
- result = max(result, day);
- st.push({v[i], day});
- }
- cout << result << endl;
- return 0;
- }
- /*
- B***C4
- BC4
- {0, 1}
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement