[백준] 📂. (2493번) 탑
🗒️ 2493번) 탑
#include <iostream>
#include <stack>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
stack<pair<int, int>> tower;
tower.push({ 100000001, 0 }); // 높이, index
for (int idx = 1; idx <= N; idx++)
{
int h;
cin >> h;
while (tower.top().first < h)
tower.pop();
cout << tower.top().second << " ";
tower.push({ h, idx });
}
return 0;
}
댓글남기기