eolymp
Problems

Soldiers Row

published at 8/21/23, 11:34:58 am

include<bits/stdc++.h>

using namespace std;

int main() {

int n, h;
cin >> n;
stack<pair<int, int>>st;
for (int i = 0; i < n; i++) {
    cin >> h;
    while (!st.empty() and st.top().first <= h) {
        st.pop();
    }
    if (st.empty()) {
        cout << "-1 ";
    }
    else if (h < st.top().first) {
        cout << st.top().second << " ";
    }
    st.push({ h,i });
}

}