import java.util.*;
class Solution {
public Map<String, Integer> parkingTimeMap = new HashMap<>();
public Map<String, Integer> inTimeMap = new HashMap<>();
public int[] solution(int[] fees, String[] records) {
int[] answer = {};
for (int i = 0; i < records.length; i++) {
String[] record = records[i].split(" ");
String[] times = record[0].split(":");
int minutes = toMinutes(times);
String carName = record[1];
String status = record[2];
System.out.println(Arrays.toString(record));
if (Objects.equals(InOut.IN.name(),status)) {
inTimeMap.put(carName, minutes);
} else {
int parkingTime = minutes - inTimeMap.remove(carName);
parkingTimeMap.put(carName, parkingTimeMap.getOrDefault(carName, 0) + parkingTime);
}
}
inTimeMap.forEach((carName, time)->{
int parkingTime = (23*60 + 59) - time;
parkingTimeMap.put(carName, parkingTimeMap.getOrDefault(carName, 0) + parkingTime);
});
int baseTime = fees[0];
int baseFee = fees[1];
int unitTime = fees[2];
int unitFee = fees[3];
TreeMap<String, Integer> sortedMap = new TreeMap<>();
parkingTimeMap.forEach((carName, time)->{
if(time <= baseTime){
sortedMap.put(carName, baseFee);
}else{
int fee = baseFee + (int)(Math.ceil((double)(time - baseTime) / unitTime)) * unitFee;
sortedMap.put(carName, fee);
}
});
return sortedMap.values().stream().mapToInt(i -> i).toArray();
}
private int toMinutes(String[] times) {
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
public enum InOut {
IN, OUT;
}
}