문제
Problem 2: Bookshelf (Silver) [Neal Wu / Traditional, 2012]
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
a new set of bookshelves to hold them all.
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
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.
PROBLEM NAME: bookshelf
입력
* Line 1: Two space-separated integers: N and L.
* Lines
and W(i). (
출력
* Line 1: The minimum possible total height for the set of bookshelves.
예제1
5 10
5 7
9 2
8 5
13 2
3 8
21
INPUT DETAILS:
There are 5 books. Each shelf can have total width at most 10.
OUTPUT DETAILS:
There are 3 shelves, the first containing just book 1 (height 5, width 7),
the second containing books 2..4 (height 13, width 9), and the third
containing book 5 (height 3, width 8).