/ ALGORITHM

프로그래머스 - 주차 요금 계산

image-20230118204208767image-20230118204239070image-20230118204314305image-20230118204339762

from collections import defaultdict
import math
def solution(fees, records):
    answer = []
    info = defaultdict(lambda: [])
    
    for i in records:
        a = i.split()
        info[a[1]].append(a[0])
        
    info = [x[1] for x in sorted(info.items(),key=lambda x: int(x[0]))]
    
    for i in info:
        fee = fees[1]
        time = 0
        
        if len(i)%2!=0:
            i.append("23:59")
            
        for j in range(0,len(i),2):
            start = int(i[j][:2])*60 + int(i[j][-2:])
            end = int(i[j+1][:2])*60 + int(i[j+1][-2:])
            time += end-start
            
        if time>fees[0]:
            fee += math.ceil((time-fees[0])/fees[2])*fees[3]
            
        answer.append(fee)
        
    return answer