[그리디] 13305

조은지·2022년 1월 10일

주유소

https://www.acmicpc.net/problem/13305

코드

n = int(input())
distance = list(map(int,input().split()))
prices = list(map(int,input().split()))

answer =0
tmp=0

for i in range(n-1):
    if prices[tmp]>prices[i+1]:
        answer+=prices[tmp]*distance[i]
        tmp=i+1#다음 주유소 갈 때 까지만
    else:
        answer+=prices[tmp]*distance[i]
print(answer)

제일 왼쪽에 도시에서 다음 도시로 갈 때까지만 주유를 한다.
만약 이전 도시의 기름값이 더 싸면 이전 도시의 가격으로 주유를 한다.
아니라면 다음 도시의 기름값으로 주유를 한다.

0개의 댓글