Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved 오큰수 - 188ms 12mb #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Baekjoon/오큰수/오큰수_조은영.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <stack>
using namespace std;

int N;
int arr[1000001];
int ans[1000001];
stack<int>s;

int main() {

ios_base::sync_with_stdio(false);
cin.tie(0);

cin >> N;

for (int i = 0; i < N; i++) {
cin >> arr[i];
}

for (int i = N - 1; i >= 0; i--) {
while (!s.empty() && s.top() <= arr[i]) s.pop();
if (s.empty()) ans[i] = -1;
else ans[i] = s.top();
s.push(arr[i]);
}

for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}

return 0;
}