티스토리 뷰

728x90
반응형

백준 13305번 주유소

백준 13305번 주유소

코드

import sys
from typing import List
input = sys.stdin.readline


class Solution:
    def gas_station(self, N: int, road: List[int], price: List[int]):
        answer = 0

        # 첫번째 주유가격을 저장
        money = price[0]

        for i in range(N-1):
            # 이전 주유가격보다 더 싼게 나오면 money를 갱신
            if price[i] < money:
                money = price[i]

            # 그때그때마다 money와 도로를 곱해서 계산해준다. 
            answer += money * road[i]
        return answer


N = int(input())
load = list(map(int, input().split()))
price = list(map(int, input().split()))
print(Solution().gas_station(N, load, price))
728x90
반응형
댓글
반응형
250x250
글 보관함
최근에 달린 댓글
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Total
Today
Yesterday
링크