diff --git "a/live11/test115/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" "b/live11/test115/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" new file mode 100644 index 00000000..2d5660cf --- /dev/null +++ "b/live11/test115/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" @@ -0,0 +1,18 @@ +import sys + +input = sys.stdin.readline + +n = int(input()) + +cnt = 0 +stack = [int(input())] +max_num = stack[-1] +for _ in range(n - 1): + num = int(input()) + if stack[-1] < num: + cnt += num - stack[-1] + max_num = max(max_num, num) + stack.pop() + stack.append(num) +cnt += max_num * len(stack) - sum(stack) +print(cnt) \ No newline at end of file diff --git "a/live11/test115/\353\254\270\354\240\2342/\353\260\225\355\235\254\352\262\275.py" "b/live11/test115/\353\254\270\354\240\2342/\353\260\225\355\235\254\352\262\275.py" new file mode 100644 index 00000000..a4e8f60f --- /dev/null +++ "b/live11/test115/\353\254\270\354\240\2342/\353\260\225\355\235\254\352\262\275.py" @@ -0,0 +1,26 @@ +import sys + + +input = sys.stdin.readline + +n = int(input()) +a = list(map(int, input().split())) + +stack = [] +res = [-1] * n +for i in range(n - 1, -1, -1): # 역순으로 + while stack and stack[-1] <= a[i]: + stack.pop() + + if stack: + res[i] = stack[-1] + + stack.append(a[i]) + +print(*res) + + +""" +4 +3 5 2 7 +""" \ No newline at end of file