#BS0000322. Chia thanh sô cô la (Divide Chocolate)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia thanh sô cô la (Divide Chocolate)
Divide Chocolate
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A chocolate bar has n consecutive chunks with positive sweetness . Make exactly k cuts between chunks, yielding k+1 nonempty consecutive pieces. You receive a piece with the smallest total sweetness. Maximize that minimum.
Input
- The first line contains integers , the number of chunks and cuts.
- The second line contains integers , sweetness values in bar order.
Output
Print the maximum possible minimum piece sweetness.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input 1
9 5
1 2 3 4 5 6 7 8 9
Output 1
6
Explanation
The six pieces (1,2,3), (4,5), (6), (7), (8), (9) have sums 6, 9, 6, 7, 8, 9. A minimum of 7 requires at least four chunks in the first piece. The five remaining chunks must form five separate pieces, including the chunk of sweetness 5, below 7. Thus 6 is optimal.
Input 2
9 8
5 6 7 8 9 1 2 3 4
Output 2
1
Explanation
Eight cuts form nine pieces from nine chunks. Each piece contains one chunk, and the least sweet chunk has value 1. No alternative partition exists.
Input 3
9 2
1 2 2 1 2 2 1 2 2
Output 3
5
Explanation
Split into three pieces (1,2,2), (1,2,2), (1,2,2), each of sum 5. The total 15 is insufficient for three pieces of sum at least 6.