폴더 분리

This commit is contained in:
2026-02-23 11:14:50 +09:00
parent 4aebd20cf5
commit 0e8e68d12f
45 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
# 주식
import sys
from collections import deque
input = sys.stdin.readline
def calculate_revenue(n, prices):
total = 0
q = deque([prices[0]])
up = 0
if prices[0] <= prices[1]:
up = 1
else:
up = 0
for i in range(1, n):
if len(q) != 0 and i == n-1 and prices[i] >= q[-1]:
high = q.pop() if i != n-1 else prices[i]
while len(q) >= 1 and q[0] > high:
q.popleft()
while len(q) >= 1:
total += (high-q.pop())
if not up:
if len(q) != 0 and prices[i] > q[-1]:
up = 1
q.append(prices[i])
continue
if len(q) != 0 and (prices[i] < q[-1] or i == n-1):
high = q.pop() if i != n-1 else prices[i]
while len(q) >= 1 and q[0] > high:
q.popleft()
while len(q) >= 1:
total += (high-q.pop())
up = 0
q.append(prices[i])
return total
def solution():
t = int(input().rstrip())
for _ in range(t):
n = int(input().rstrip())
prices = list(map(int, input().rstrip().split()))
print(calculate_revenue(n, prices))
return
solution()
"""
걸린 시간:
시간 복잡도:
해설:
"""