We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7245a24 commit 4189797Copy full SHA for 4189797
1 file changed
live11/test115/문제2/박희경.py
@@ -0,0 +1,26 @@
1
+import sys
2
+
3
4
+input = sys.stdin.readline
5
6
+n = int(input())
7
+a = list(map(int, input().split()))
8
9
+stack = []
10
+res = [-1] * n
11
+for i in range(n - 1, -1, -1): # 역순으로
12
+ while stack and stack[-1] <= a[i]:
13
+ stack.pop()
14
15
+ if stack:
16
+ res[i] = stack[-1]
17
18
+ stack.append(a[i])
19
20
+print(*res)
21
22
23
+"""
24
+4
25
+3 5 2 7
26
0 commit comments