We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 16f4225 + 3c7f138 commit fa90bcbCopy full SHA for fa90bcb
2 files changed
live11/test115/문제1/박희경.py
@@ -0,0 +1,18 @@
1
+import sys
2
+
3
+input = sys.stdin.readline
4
5
+n = int(input())
6
7
+cnt = 0
8
+stack = [int(input())]
9
+max_num = stack[-1]
10
+for _ in range(n - 1):
11
+ num = int(input())
12
+ if stack[-1] < num:
13
+ cnt += num - stack[-1]
14
+ max_num = max(max_num, num)
15
+ stack.pop()
16
+ stack.append(num)
17
+cnt += max_num * len(stack) - sum(stack)
18
+print(cnt)
live11/test115/문제2/박희경.py
@@ -0,0 +1,26 @@
+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]:
+ if stack:
+ res[i] = stack[-1]
+ stack.append(a[i])
19
20
+print(*res)
21
22
23
+"""
24
+4
25
+3 5 2 7
26
0 commit comments