목록swift 알고리즘/그리드 (3)
쥐수의 공부노트

정답 : let n = Int(readLine()!)! let distance = readLine()!.split(separator: " ").map{Int($0)!} let price = readLine()!.split(separator: " ").map{Int($0)!} var result = 0 var minValue = price[0] for i in 0.. price[i] { minValue = price[i] } result += minValue * distance[i] } print(result) 해당 문제는 distance와 price를 곱한 뒤 result에 더하면 된다. 하지만, 가격을 측정해야 하기에, minValue 와 다음 주유소의 가격을 비교하여, 가격이 낮은 주유소의 값을 가져..

정답 : let input = readLine()!.split(separator: "-") var result = 0 for i in input[0].split(separator: "+") { result += Int(i)! } for i in input[1...] { for j in i.split(separator: "+") { result -= Int(j)! } } print(result) 해당 문제는 수식을 받는데, -를 기점으로 받는다. 예를 들어, 10 + 20 - 30 - 40 + 50 - 60 이 있다고 치자. 우리가 구한 최솟값은 10 + 20 - 30 - (40 + 50) - 60 이 될것이다. -로 split을 주었기 때문에, input[0] 에는 10 + 20 , input[1]에는 ..