PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000257. Chiều rộng nhỏ nhất (Minimum Width)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chiều rộng nhỏ nhất (Minimum Width)
Minimum Width
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi displays words in order; word has width . Words cannot be split. Each line starts at the left edge; neighboring words on a line have a gap of width 1. Find the smallest integer window width fitting the sentence in at most lines.
Input
The first line contains integers , the word count and line limit. The second contains the integer word widths .
Output
Print the minimum integer width.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all . .
- Subtask 3 (50 points): ; for all .
Examples
Input
5 2
2 3 4 1 2
Output
9
Explanation
The first two words need width 6 and the last three need 9. At width 8 the first line cannot include word 3 (the first three require 11), leaving words requiring at least 9. Thus 9 is optimal.