Language: C++

// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_4-D: Allocation

#include <algorithm>
#include <cstdio>
#include <numeric>
#include <vector>
using namespace std;

using uint = unsigned int;

static bool is_loaded(uint max_load, uint num, const vector<uint>& ws)
{
  const auto last = ws.end();
  auto it = ws.begin();
  for (auto i = 0u; i < num; ++i) {
    auto capacity = max_load;
    while (it < last && *it <= capacity) {
      capacity -= *it++;
    }
    if (it == last) return true;
  }
  return false;
}

static uint min_load_capacity(uint num, const vector<uint>& ws)
{
  const auto ws_sum = accumulate(ws.begin(), ws.end(), 0);
  const auto max_w = max_element(ws.begin(), ws.end());

  auto left = max(max_w, (ws_sum-1)/num+1);
  auto right = ws_sum;
  while (left < right) {
    const auto middle = (left+right)/2;
    if (is_loaded(middle, num, ws)) {
      right = middle;
    } else {
      left = middle+1;
    }
  }
  return right; // right == left;
}

int main()
{
  uint n, k;
  scanf("%u %u", &n, &k);

  vector<uint> ws(n);
  for (auto i = 0u; i < n; ++i) {
    scanf("%u", &ws[i]);
  }

  auto c = min_load_capacity(k, ws);
  printf("%u\n", c);
}

// eof

Compiler output:
a.cc: In function 'uint min_load_capacity(uint, const std::vector<unsigned int>&)':
a.cc:31:18: error: no matching function for call to 'max(const __gnu_cxx::__normal_iterator<const unsigned int*, std::vector<unsigned int> >&, uint)'
   31 |   auto left = max(max_w, (ws_sum-1)/num+1);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:18: note:   deduced conflicting types for parameter 'const _Tp' ('__gnu_cxx::__normal_iterator<const unsigned int*, std::vector<unsigned int> >' and 'uint' {aka 'unsigned int'})
   31 |   auto left = max(max_w, (ws_sum-1)/num+1);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:18: note:   '__gnu_cxx::__normal_iterator<const unsigned int*, std::vector<unsigned int> >' is not derived from 'std::initializer_list<_Tp>'
   31 |   auto left = max(max_w, (ws_sum-1)/num+1);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~