IT/알고리즘
[백준] 16917번 양념 반 후라이드 반
남갯
2024. 12. 11. 23:50
728x90
SMALL
https://www.acmicpc.net/problem/16917
fun main() = with(Scanner(System.`in`)) {
val sauce = nextInt()
val original = nextInt()
val half = nextInt()
val sauceCount = nextInt()
val originalCount = nextInt()
val needHalf = half * 2 < original + sauce
val maxHalfCount = if (needHalf) min(originalCount, sauceCount) else 0
var total = 0
if (needHalf) {
total += maxHalfCount * (2 * half)
}
val originalTotal = ((originalCount - maxHalfCount) * original) + ((sauceCount - maxHalfCount) * sauce)
val halfTotal = half * 2 * max(originalCount - maxHalfCount, sauceCount - maxHalfCount)
total += min(originalTotal, halfTotal)
println(total)
}
728x90
LIST