Language: C++

#include <cstdio>
#include <vector>
#include <map>
using namespace std;

struct index_tt {
	int total;
	int truck;
};

bool operator<(index_tt& lhs, index_tt& rhs) {
	if(lhs.total<rhs.total) {
		return true;
	} else if(lhs.total==rhs.total && lhs.truck<rhs.truck) {
		return true;
	} else {
		return true;
	}
}

map<index_tt,int> pack;

int make_min_packing(index_tt nq,vector<int>& sum) {
	int m;
	index_tt temp;
	if(nq.truck==1) {
		m=sum[nq.total-1];
		pack[nq]=m;
	} else {
		for(int i=1; i<=nq.total-nq.truck+1; ++i) {
			temp.total=nq.total-i;
			temp.truck=nq.truck-1;
			if(pack.find(temp)==pack.end()) {
				pack[temp]=make_min_packing(temp,sum);
			}
			m=min(m,max(pack[temp],sum[nq.total-1]-sum[nq.total-i-1]));
		}
	}
	return m;
}

int main() {
	int n,q,w;
	vector<int> sum;
	index_tt idx;
	scanf("%d%d",&n,&q);
	sum.resize(n);
	idx.total=n;
	idx.truck=q;
	scanf("%d",&sum[0]);
	for(int i=1; i<n; ++i) {
		scanf("%d",&w);
		sum[i]=sum[i-1]+w;
	}
	printf("%d\n",make_min_packing(idx,sum));
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/refwrap.h:39,
                 from /usr/include/c++/14/vector:68,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = index_tt]':
/usr/include/c++/14/bits/stl_map.h:511:32:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = index_tt; _Tp = int; _Compare = std::less<index_tt>; _Alloc = std::allocator<std::pair<const index_tt, int> >; mapped_type = int; key_type = index_tt]'
  511 |         if (__i == end() || key_comp()(__k, (*__i).first))
      |                             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:28:10:   required from here
   28 |                 pack[nq]=m;
      |                        ^
/usr/include/c++/14/bits/stl_function.h:405:20: error: no match for 'operator<' (operand types are 'const index_tt' and 'const index_tt')
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
a.cc:11:6: note: candidate: 'bool operator<(index_tt&, index_tt&)' (near match)
   11 | bool operator<(index_tt& lhs, index_tt& rhs) {
      |      ^~~~~~~~
a.cc:11:6: note:   conversion of argument 2 would be ill-formed:
a.cc:11:6: error: binding reference of type 'index_tt&' to 'const index_tt' discards qualifiers
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/vector:62:
/usr/include/c++/14/bits/stl_pair.h:1045:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1045 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1045:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const index_tt' is not derived from 'const std::pair<_T1, _T2>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const index_tt' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const index_tt' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const index_tt' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const index_tt' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:2089:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2089 |     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:2089:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const index_tt' is not derived from 'const std::vector<_Tp, _Alloc>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~