가장 큰 값 - 가장 작은 값 을 서서히 더해가는게 가장 높은 값에 근사하기 때문임(그리드 알고리즘)
즉, 이를 식으로 풀면
fun main() {
question1758()
}
fun question1758() {
val case = readln().toInt()
val tip = mutableListOf<Long>()
for(i in 1 .. case) {
tip.add(readln().toLong())
}
var upperCase = 0L
tip.sortedDescending().forEachIndexed { index, i ->
(i - index).let {
if(it > 0) upperCase += it
}
}
println("$upperCase")
}