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

#BS0000280. Chia mảng tối ưu (Splitting an Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chia mảng tối ưu (Splitting an Array)

Splitting an Array

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Partition a positive integer array into exactly kk nonempty contiguous blocks, each element belonging to exactly one block. Minimize the largest block sum. This PHOJ adaptation uses locally defined limits.

Input

First line: n,kn,k. Second line: nn integers aia_i.

Output

Print the optimal value.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤121\le k\le n\le12; 1≤ai≤1001\le a_i\le100.
  • Subtask 2 (30 points): 1≤k≤n≤2⋅1051\le k\le n\le2\cdot10^5; 1≤ai≤1091\le a_i\le10^9; a1=⋯=ana_1=\cdots=a_n.
  • Subtask 3 (50 points): 1≤k≤n≤2⋅1051\le k\le n\le2\cdot10^5; 1≤ai≤1091\le a_i\le10^9.

Examples

Input 1

5 3
2 4 7 3 5

Output 1

8

Explanation

Blocks [2,4], [7], [3,5] have sums 6,7,8. A cap of 7 needs at least four blocks.