728x90
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)
}
728x90
LIST