본문 바로가기

IT/알고리즘

[백준] 16917 양념 반 후라이드 반

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

'IT > 알고리즘' 카테고리의 다른 글

[백준] 14502 연구소  (0) 2024.12.16
[백준] 11651번 좌표정렬하기_2  (3) 2024.12.09
[백준] 14225번 부분수열의 합  (0) 2024.12.09
[백준] 차량번호판  (0) 2024.12.05
[백준] 적록 색약  (1) 2024.12.04