cswork / OAOpen practice workspace

MathWorksOA #14

Load Balancing

Estimated MediumJudge-ready

Topics (AI-labelled)Binary SearchGreedy

Assign m tasks in the given order to n resources so that each resource receives a non-empty contiguous range of tasks. Minimize the maximum total load over all resources.

See below for this site's input/output protocol.

Input

The first line contains n m, and the next line contains m processing times. 1≤n≤m≤100000, 1≤burstTime[i]≤10000.

Output

Output the minimum possible maximum resource load.

Example 1

Input:

3 5
7 2 3 4 5

Output:

9

Example 2

Input:

2 3
1 1 1

Output:

2

Example 3

Input:

1 3
1 2 3

Output:

6

Editorial

Loading solution…