PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000324. Hoàn thành mọi công việc (Find Minimum Time to Finish All Jobs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hoàn thành mọi công việc (Find Minimum Time to Finish All Jobs)

Find Minimum Time to Finish All Jobs

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn independent jobs and kk workers. Job ii takes aia_i units of time and must be assigned entirely to one worker.

A worker performs assigned jobs sequentially, spending their total duration, or zero time if no job is assigned. Different workers may work simultaneously.

Assign every job so that the greatest workload among the workers is as small as possible.

Input

The first line contains two integers n,kn,k, the numbers of jobs and workers.

The second line contains nn integers a1,…,ana_1,\ldots,a_n, the job durations.

Output

Print one integer: the smallest possible maximum workload.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤71\le k\le n\le7; 1≤ai≤1071\le a_i\le10^7.
  • Subtask 2 (30 points): 1≤k≤n≤121\le k\le n\le12; 1≤ai≤1071\le a_i\le10^7; k≤2k\le2.
  • Subtask 3 (50 points): 1≤k≤n≤121\le k\le n\le12; 1≤ai≤1071\le a_i\le10^7.

Examples

Input 1

5 2
1 2 4 7 8

Output 1

11

Explanation

Assign durations 1, 2, 8 to one worker and 4, 7 to the other. Each works for 11 units. Since total work is 22, at least one worker must spend at least 11 units.

Input 2

3 3
3 2 3

Output 2

3

Explanation

Give each worker one job, with durations 3, 2 and 3. A job of duration 3 cannot be split, so 3 is also a lower bound.