IT/알고리즘

[백준] 블랙잭 - 브루트포스

남갯 2024. 10. 23. 20:26
SMALL

 

https://www.acmicpc.net/problem/2798

fun main() = with(Scanner(System.`in`)) {
    val count = nextInt()
    val maxSize = nextInt()
    val items = arrayOfNulls<Int>(count)
    for (i in 0 until count) {
        items[i] = nextInt()
    }

    var max = 0
    for (i in items.indices) {
        for (j in (i + 1) until items.size) {
            for (k in (j + 1) until items.size) {
                val sum = items[i]!! + items[j]!! + items[k]!!
                if (sum in max.. maxSize) {
                    max = sum
                }
            }
        }
    }


    println(max)
}
LIST