백준 13305 주유소

김민영·2022년 12월 29일
0

알고리즘

목록 보기
12/125

주유소

계획

  • 주유소를 보면서 거리를 누적함. 이전 주유소보다 가격이 싸지면, 누적된 거리만큼 이전 주유소 값으로 계산하여 저장, 거리 초기화.
N = int(input())
distances = list(map(int, input().split()))
stations = list(map(int, input().split()))
oil = 0
dis = 0
tmp = stations[0]
dist = 0

for i in range(N):
    if i == N - 1:
        oil += dist * tmp
        continue
    now = stations[i]
    if tmp > now:
        oil += dist * tmp
        tmp = now
        dist = 0
    dist += distances[i]

print(oil)
profile
노션에 1차 정리합니당 - https://cream-efraasia-f3c.notion.site/4fb02c0dc82e48358e67c61b7ce8ab36?v=

0개의 댓글