#P1295. [TJOI2011] 书架
[TJOI2011] 书架
Description
You are given, in a fixed order, all the books to be placed on the bookshelf. There are books, and the -th book has a length .
The bookshelf has several layers (shelves). The widths of different layers may vary, but the width of a layer cannot be smaller than the length of any book placed on that layer. At the same time, the sum of the lengths of the books on each layer cannot exceed a given parameter , and the books on any layer must be a contiguous subsequence in the given order.
The width of the bookshelf is the sum of the widths of all layers. Find the minimum possible width of the bookshelf.
Input Format
The first line contains two integers and .
From line to line , each line contains one integer. The integer on line is the length of the -th book.
Output Format
Output a single integer on one line representing the answer.
4 6
1
3
3
1
5
Hint
Constraints
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , .
Hint
Because the original statement was quite ambiguous, here is a simplified version:
Given a sequence of length , partition into several segments such that the sum of numbers in each segment does not exceed , and minimize the sum of the maximum values of all segments.
Translated by ChatGPT 5
京公网安备 11011102002149号