#include <bits/stdc++.h>
using namespace std;
int n, a[1000002];
void solve() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
stack<int> st, ans;
for (int i = n - 1; i >= 0; --i) {
while (!st.empty() && st.top() <= a[i]) {
st.pop();
}
if (st.empty()) {
ans.push(-1);
} else {
ans.push(st.top());
}
st.push(a[i]);
}
while (!ans.empty()) {
cout << ans.top() << ' ';
ans.pop();
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}'PS' 카테고리의 다른 글
| 백준 BOJ 2468 C++ 안전영역 (0) | 2026.04.15 |
|---|---|
| 백준 BOJ 5014 C++ 스타트링크 (0) | 2026.04.15 |
| 백준 1021 C++ [boj 1021 회전하는 큐] (0) | 2026.04.15 |
| 백준 3986 C++ [boj 3986 좋은 단어] (0) | 2026.04.15 |
| boj 6198 c++ [백준 6198, 옥상 정원 꾸미기] (0) | 2026.04.14 |