출처 : 백준, https://www.acmicpc.net/problem/13305
더보기
첫 번째 풀이 : 58점
n = int(input())
diss = list(map(int, input().split()))
prices = list(map(int, input().split()))
prev_price = 99999
answer = 0
for index in range(n-1):
if prev_price > prices[index]:
prev_price = prices[index]
answer += prev_price * diss[index]
print(answer)
두 번째 풀이 : 58점
end = int(input())
diss = list(map(int, input().split()))
prices = list(map(int, input().split()))
answer = 0
while True:
min_price = min(prices[0:end])
min_index = prices.index(min_price)
answer += sum(diss[min_index:end] * min_price)
end = min_index
if end <= 0:
break
print(answer)
세 번째 풀이 : 100점
n = int(input())
diss = list(map(int, input().split()))
prices = list(map(int, input().split()))
prev_price = 99999
answer = 0
for index in range(n-1):
if prev_price > prices[index]:
prev_price = prices[index]
answer += prev_price * diss[index]
print(answer)
시간 복잡도
-
다른 사람의 풀이를 보면서 알게 된 점
-
고찰
서브테스크가 모징모징하다가 틀림....
'알고리즘 > Python' 카테고리의 다른 글
[python] 백준 1932 - 정수 삼각형 (0) | 2022.05.07 |
---|---|
[python] 백준 1874 - 스택 수열 (0) | 2022.05.07 |
[python] 백준 1057 - 토너먼트 (0) | 2022.04.08 |
[python] 백준 2529 - 부등호 (0) | 2022.04.07 |
[python] 백준 1072 - 게임 (0) | 2022.04.07 |