From 4189797357b4efaeb1f3a799e6481f0a7a8f8fbb Mon Sep 17 00:00:00 2001 From: gmlrude Date: Fri, 2 May 2025 15:07:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?115=EC=B0=A8=202=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4(=EC=B0=B8=EA=B3=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\225\355\235\254\352\262\275.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "live11/test115/\353\254\270\354\240\2342/\353\260\225\355\235\254\352\262\275.py" 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 From c734bffb1800188bcaddad54fcafb244615aeae3 Mon Sep 17 00:00:00 2001 From: gmlrude Date: Fri, 2 May 2025 15:07:29 +0900 Subject: [PATCH 2/3] =?UTF-8?q?115=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4(=ED=91=B8=EB=8A=94=EC=A4=91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\225\355\235\254\352\262\275.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "live11/test115/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" 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..a5de5202 --- /dev/null +++ "b/live11/test115/\353\254\270\354\240\2341/\353\260\225\355\235\254\352\262\275.py" @@ -0,0 +1,16 @@ +import sys + +input = sys.stdin.readline + +n = int(input()) +a = [] +for _ in range(n): + a.append(int(input())) + +cnt = 0 +stack = [] +for num in a: + if not stack: + stack.append(num) + else: + if num > stack[-1]: From 3c7f1385cbf9def0d8daab7012e0493a35fd51e3 Mon Sep 17 00:00:00 2001 From: gmlrude Date: Mon, 5 May 2025 11:54:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?115=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4(=EC=B0=B8=EA=B3=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\225\355\235\254\352\262\275.py" | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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" index a5de5202..2d5660cf 100644 --- "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" @@ -3,14 +3,16 @@ input = sys.stdin.readline n = int(input()) -a = [] -for _ in range(n): - a.append(int(input())) cnt = 0 -stack = [] -for num in a: - if not stack: - stack.append(num) - else: - if num > stack[-1]: +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