#BS0000022. Rót đầy các thùng chứa (Fill the Containers)
Rót đầy các thùng chứa (Fill the Containers)
Fill the Containers
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are vessels in a fixed conveyor-belt order, and vessel contains units of milk. All milk from one vessel must be poured into exactly one container; a vessel may not be split between containers.
Number the containers from to . The vessel order must be preserved: if vessel comes before vessel , and they are poured into containers and , respectively, then
Thus, the vessels assigned to each used container form a contiguous segment of the original sequence. Some containers may remain unused.
The containers do not have to have the same capacity. Each container may be assigned its own capacity. Minimize the largest capacity among the used containers. Equivalently, find the smallest such that all milk can be transferred in order using at most containers and the total milk poured into every used container is at most .
Input
The first line contains . The second line contains .
Output
Print the minimum possible value of the maximum container capacity.
Subtasks
- Subtask 1 — 20%: or .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: , , .
Examples
Input
5 3
1 2 3 4 5
Output
6
Explanation
The groups , , and require maximum capacity , which is optimal.