fun main(args: Array<String>) {
    val list: List<String> = readLine()!!.split(" ").map { it.toString() }
    var weightList = mutableListOf<Int>()
    for (i in (0..list[0].toInt()-1))
    {
        weightList.add(readLine()!!.toInt())
    }
    var trackCnt=  list[1].toInt()
    if (trackCnt == 1)
    {
        println(weightList.sum().toString())
        return
    }
    var mid = Math.ceil((weightList.sum().toDouble() / trackCnt.toDouble())).toInt()
    if (mid < weightList.max()!!)
    {
        mid = weightList.max()!!
    }
    //println(weightList.sum())
    var cnt:Int
    var w:Int
    val weightTotal = weightList.sum()
    //最適weight探索
    for (j in (mid..weightTotal-1)) {
        //println("j"+j.toString())
        w = j
        cnt = 0
        for (i in (0..weightList.count() - 1)) {
            if (w >= weightList[i]) {
                w = w - weightList[i]
                //println("weight:"+w.toString())
                if (w==0)
                {
                    cnt++
                    //println("cnt:"+cnt.toString())
                    w = j
                }
            } else {
                cnt++
                //println("cnt:"+cnt.toString())
                w = j - weightList[i]
                //println("weight:"+w.toString())
            }
            if (cnt > trackCnt)
            {
                //println(j.toString()+"break")
                break
            }
            else if((trackCnt!= cnt) && ((weightTotal - (cnt * j)) / (trackCnt - cnt)) > j)
            {
                break
            }
        }
        if (w!=j)
        {
            cnt++
        }
        if (cnt <= trackCnt) {
            println(j)
            break
        }
    }
}

