using System;
using System.Collections.Generic;
using System.Linq;
// Q014 二分探索と貪欲法 https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D&lang=jp
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5 3");
WillReturn.Add("8");
WillReturn.Add("1");
WillReturn.Add("7");
WillReturn.Add("3");
WillReturn.Add("9");
//10
}
else if (InputPattern == "Input2") {
WillReturn.Add("4 2");
WillReturn.Add("1");
WillReturn.Add("2");
WillReturn.Add("2");
WillReturn.Add("6");
//6
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long mK;
static long[] mWeightArr;
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray();
mK = wkArr[1];
mWeightArr = InputList.Skip(1).Select(X => long.Parse(X)).ToArray();
//二分法で解く
long L = 0;
long R = int.MaxValue;
long Mid = (L + R) / 2;
while (L + 1 < R) {
//Console.WriteLine("L={0},Mid={1},R={2}", L, Mid, R);
if (CanTousai(Mid)) {
R = Mid;
}
else {
L = Mid;
}
Mid = (L + R) / 2;
}
Console.WriteLine(R);
}
// 最大積載量Pを引数として、全ての荷物を搭載可能かを返す
static bool CanTousai(long pP)
{
if (mWeightArr.Max() > pP) {
return false;
}
long CurrSum = 0;
long TrackCnt = 1;
for (int I = 0; I <= mWeightArr.GetUpperBound(0); I++) {
if (CurrSum + mWeightArr[I] > pP) {
CurrSum = mWeightArr[I];
TrackCnt++;
if (TrackCnt > mK) {
return false;
}
}
else {
CurrSum += mWeightArr[I];
}
}
return true;
}
}