From f0cd4968828eb269958bba23ea912e85ec32bd5a Mon Sep 17 00:00:00 2001 From: nkey Date: Fri, 30 Jan 2026 13:24:47 +0900 Subject: [PATCH] =?UTF-8?q?13305-s3=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workbook_8708/13305-s3.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 workbook_8708/13305-s3.py diff --git a/workbook_8708/13305-s3.py b/workbook_8708/13305-s3.py new file mode 100644 index 0000000..fd25e65 --- /dev/null +++ b/workbook_8708/13305-s3.py @@ -0,0 +1,35 @@ +# 주유소 + +import sys + +input = sys.stdin.readline + +def solution(): + n = int(input().rstrip()) + dist = list(map(int, input().rstrip().split())) + price = list(map(int, input().rstrip().split())) + + least_price = float('inf') + + result = 0 + for i in range(n-1): + if price[i] < least_price: + least_price = price[i] + result += (dist[i]*least_price) + + + print(result) + return + +solution() + + + +""" +걸린 시간: 12분 + +시간 복잡도: dist 길이만큼 한 번 돌기 때문에 전체 시간복잡도는 O(n)이다. + +해설: 현재 지역 다음에 본인보다 더 싼게 있으면 거기까지만 가고 그 다음부터는 싼 곳에서 기름을 사야한다. +가장 쌌던 가격을 계속 기록해가면서 price를 마지막-1 까지 순회하면 끝. +""" \ No newline at end of file