编辑代码

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
  const arr = (await readline())
    .split(" ")
    .map(Number)
    .sort((a, b) => b - a);
  const n = Number(await readline());
  let min = arr[0];
  let max = arr.reduce((a, b) => a + b);
  let ans = max;
  while (min <= max) {
    const mid = (min + max) >> 1;
    if ((check(arr, 0, new Array(n).fill(0)), mid)) {
      ans = mid;
      max = mid - 1;
    } else {
      min = mid + 1;
    }
  }
  console.log(ans);
})();
const check = (balls, idx, buckets, limit) => {
  if (idx == balls.length) return true;
  const selected = balls[idx];
  for (let i = 0; i < buckets.length; i++) {
    if (selected + buckets[i] <= limit) {
      buckets[i] += selected;
      if (check(balls, idx + 1, buckets, limit)) return true;
      buckets[i] -= selected;
    }
  }
  return false;
};