문제 링크 (opens new window)

# 풀이

딕셔너리로 풀이, 떠나는 시간이라는 문구 주의

import Foundation

let input: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
var trucks: [(Int, Int)] = []
var min = 100
var max = 0
var dict: [Int: Int] = [:]

for _ in 0..<3 {
    let time = readLine()!.split(separator: " ").map { Int($0)! }

    min = time[0] < min ? time[0] : min
    max = time[1] > max ? time[1] : max

    trucks.append((time[0], time[1]))
}


for time in trucks {
    for t in time.0..<time.1 {
        if let _ = dict[t] {
            dict[t]! += 1
        } else {
            dict[t] = 1
        }
    }
}

var result = 0
for t in min..<max {
    switch dict[t] {
    case 1:
        result += input[0]
    case 2:
        result += input[1] * 2
    case 3:
        result += input[2] * 3
    default:
        continue
    }
}

print(result)