//单调栈
#include<iostream>
using namespace std;
const int N=1010;
int n,stk[N],tt;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
while(tt && stk[tt]>=x) tt--;
if(tt) cout<<stk[tt]<<' ';
else cout<<-1<<' ';
stk[++tt]=x;
}
return 0;
}
05-05
1186
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-29
1934
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-10