cswork / OAOpen practice workspace

AmazonOA #135

Minimum Memory for Hard Drives

Estimated MediumJudge-ready

Topics (AI-labelled)Binary SearchGreedy

Distribute all games among N children; games cannot be split, and every child gets at least one. Any grouping is allowed; groups need not be contiguous in the original array. All disks have the same capacity; find the minimum capacity that fits the distribution. This site uses small sizes that can be solved exactly, and does not substitute contiguous partitioning for arbitrary distribution.

Input

The first line contains m N, and the second line contains m game sizes. On this site 1≤N≤m≤15 and 1≤size≤10⁹; these upper bounds are not constraints provided by the source.

Output

Output a single integer answer.

Example 1

Input:

5 3
6 7 10 12 1

Output:

13

Example 2

Input:

3 2
8 8 8

Output:

16

Example 3

Input:

3 3
3 9 2

Output:

9

Example notes

Example 1: split into 6+7, 12+1 and 10, with a maximum of 13; with capacity 12, 12 takes a disk alone, 10 can pair with at most 1, and 6 and 7 cannot share a disk, so at least 4 disks are needed; the optimum is 13. Example 2: some child must take two 8s, so the capacity is 16. Example 3: each child gets one game, so the capacity is the maximum, 9.

Editorial

Loading solution…