https://www.acwing.com/problem/content/832/
#include <iostream> using namespace std; const int N = 100010; int stk[N], tt; int main() { int n; cin >> n; while (n -- ) { int x; Scanf ( " % D " , & X); the while (TT && STK [TT]> = X) // if the stack is not empty and the stack of elements is greater than the current figure, then the stack of elements is not will be used TT - ; IF (! TT) the printf ( " -1 " ); // if is greater than, is not described, it outputs -1 the else the printf ( " % D " , STK [TT]); // If there is less than, the outputs STK [TT ++] = x; // then go into the x } return 0 ; }