swift 알고리즘/그리드
백준 13305번 주유소
쥐수
2023. 8. 3. 17:37
728x90
정답 :
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..<n-1 {
if minValue > price[i] {
minValue = price[i]
}
result += minValue * distance[i]
}
print(result)
해당 문제는 distance와 price를 곱한 뒤 result에 더하면 된다.
하지만, 가격을 측정해야 하기에, minValue 와 다음 주유소의 가격을 비교하여, 가격이 낮은 주유소의 값을 가져와 계산!
728x90