(function main(){
  let lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n");
  let [n, k] = lines.shift().split(' ').map(Number);
  let w = lines.map(Number);
  // console.log(w);
  let sum = w.reduce((p, c) => p + c, 0);
  if (k == 1) {console.log(sum);return;}
  let t = [], t2 = [];
  for (let i = 0; i < k; i++){t[i] = 0;t2[i] = []};
  let avg = sum / (k);

  let cnt = 0;
  w.forEach(function(e) {
    if (avg - (2 * t[cnt] + e) / 2 > 0) {
    } else {
      avg = sum / (k - cnt - 1);
      // console.log(sum, avg);
      cnt++;
    }
    avg = sum / (k - cnt - 1);
    sum -= e;
    t[cnt] += e;
    t2[cnt].push(e);
    // console.log(t, t2);
  });

  while(true) {
    let flg = false;
    for (let i = 0;i < k - 1;i++) {
    // console.log(t[i], t[i+1]　+ t2[i][0]);
    // console.log(t[i] - t2[i][k-1], t[i+1]);
      if (t[i] > t[i+1]　+ t2[i][0]) {
        const tmp = t2[i].shift()
        t[i] -= tmp;
        t[i+1] += tmp;
        flg = true;
      } else if (t[i] - t2[i][k-1] > t[i+1]) {
        const tmp = t2[i].pop()
        t[i] += tmp;
        t[i+1] -= tmp;
        flg = true;
      }
    }
    if (!flg) break;
  }
  console.log(t.sort((a,b)=>b-a)[0]);
})();

