폴더 분리
This commit is contained in:
35
workbook_8708/silver/13305-s3.py
Normal file
35
workbook_8708/silver/13305-s3.py
Normal file
@@ -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 까지 순회하면 끝.
|
||||
"""
|
||||
Reference in New Issue
Block a user