본문 바로가기
Algorithm

[구현/수학] 백준 18330 Petrol - 파이썬(Python)

by jangThang 2022. 8. 26.
반응형

백준 온라인 저지

 

[ Contents ]

     

     

    1. 문제 (링크 참조)

     

    18330번: Petrol

    The input consists of two lines. The first line contains an integer n (0 ⩽ n ⩽ 200), specifying the amount of petrol that will be used in the next month. The second line contains an integer k (0 ⩽ k ⩽ 360), showing the quota left in Mahya’s fuel

    www.acmicpc.net

     

     

     

    2. 문제 풀이

     매달 60리터는 1500 Oshloobs로 싸게 쌀 수 있습니다. 하지만, 60리터를 초과하면 2배로 비싼 3000 Oshloobs를 지불해야 합니다.

     다음 달에 사용할 기름의 양과, 이번 달에 남은 할당량(1500에 살 수 있는 양)이 주어질 때 필요한 지불비용을 구합니다.

     

     

     

    3. 코드

    # 입력
    n = int(input())
    k = int(input())
    
    # 계산
    cost = 0
    cheap = k+60  # 1500에 살 수 있는 양
    
    if n <= cheap:
        print(n*1500)
    else:
        print(cheap*1500 + (n-cheap)*3000)

     1500 Oshloobs에 살 수 있는 할당량은 '지난 달에 남은 할당량 + 다음 달에 새로 들어오는 60'입니다. 먼저 싸게 살 수 있는 1500 Oshloobs 짜리를 쓰고, 그 다음에 초과비용을 지불합니다.

     

    star가 되고나서 Tistory

    반응형

    댓글