#8172. [USACO12OPEN] Bookshelf G

    ID: 8172 传统题 1000ms 125MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P1848动态规划 DP2012线段树二分USACO平衡树动态规划优化

[USACO12OPEN] Bookshelf G

[USACO12OPEN] Bookshelf G

题目描述

When Farmer John isn't milking cows, stacking haybales, lining up his cows, or building fences, he enjoys sitting down with a good book. Over the years, he has collected N books (1 <= N

Each book i has a width W(i) and height H(i). The books need to be added to a set of shelves in order; for example, the first shelf should contain books 1...k for some k, the second shelf should start with book k+1, and so on. Each shelf can have a total width of at most L (1 <= L <= 1,000,000,000). The height of a shelf is equal to the height of the tallest book on that shelf, and the height of the entire set of bookshelves is the sum of the heights of all the individual shelves, since they are all stacked vertically.

Please help FJ compute the minimum possible height for the entire set of bookshelves.

输入格式

Line 1: Two space-separated integers: N and L. Lines 2..1+N: Line i+1 contains two space-separated integers: H(i) and W(i). (1 <= H(i) <= 1,000,000; 1 <= W(i)

输出格式

Line 1: The minimum possible total height for the set of bookshelves.
5 10
5 7
9 2
8 5
13 2
3 8
21

提示

(暂无提示) 标签: P1848|动态规划 DP|2012|线段树|二分|USACO|平衡树|动态规划优化

来源

P1848|[USACO12OPEN] Bookshelf G