Problem:
Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 10^9

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192

Solution in Kotlin (1.3.71) (judge verdict: Wrong Answer)

import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*

class PriQueMax<T>() :
        PriorityQueue<T>(Collections.reverseOrder()) {}

private data class State(val leng: Double, val cnt: Int, val idx: Int): Comparable<State> {
    override operator fun compareTo(other: State): Int {
        if (this.leng > other.leng) return 1
        if (this.leng < other.leng) return -1
        return 0
    }
}

fun bsCondOpCl(A: LongArray, L: Double, R: Double, K: Int): Long {
    val N = A.size

    fun isCondition(A: LongArray, m: Double): Boolean {
        val pq = PriQueMax<State>()
        for (i in 0 until N) {
            pq.add(State(A[i].toDouble(), 1, i))
        }

        for (k in 0 until K) {
            var (leng, cnt, i) = pq.poll()
            cnt++
            pq.add(State(A[i].toDouble()/cnt, cnt, i))
        }

        val sts = pq.poll()!!
        return sts.leng <= m
    }

    var l = L; var r = R

    while (l+1e-2 < r) {
        val m = (l + r) / 2.0
        if (isCondition(A, m)) {
            r = m
        } else {
            l = m
        }
    }
    return ceil(r).toLong()
}


fun solve() {
    val (N, K) = rd.readIntArray()
    val A = rd.readLongArray().sorted()
    assert(A.size == N) {"A.size == N"}

    if (K==0) {
        println(A.last())
        return
    }

    val ans = bsCondOpCl(A.toLongArray(), 0.0, A.last().toDouble(), K)

    print(ans)
}


//val rd = debug.Reader("abc", "174", "e", "sample-3")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}