A logistics company has
The packages must be split among
The load of a van is the sum of the weights of the packages it carries. Find the minimum possible value of the maximum load carried by any single van, over all valid ways to split the
The first line contains two integers KaTeX can only parse string typed expression and KaTeX can only parse string typed expression — the number of packages and the number of vans.
The second line contains KaTeX can only parse string typed expression integers KaTeX can only parse string typed expression — the weights of the packages, in route order.
Print a single integer — the minimum possible value of the maximum van load.
Input
4 2
10 20 30 40Output60ExplanationThe best split is KaTeX can only parse string typed expression and KaTeX can only parse string typed expression, with loads KaTeX can only parse string typed expression and KaTeX can only parse string typed expression. The maximum load is KaTeX can only parse string typed expression, and no split into 2 groups can do better.
Example 2:
Input
4 1
5 5 5 5Output20ExplanationWith only 1 van, it must carry everything, so the load is the total sum, KaTeX can only parse string typed expression.
Example 3:
Input
4 4
1 2 3 4Output4ExplanationWith exactly as many vans as packages, each van carries exactly one package, so the maximum load is simply the heaviest single package, KaTeX can only parse string typed expression.