#QHD0000022. Đám mây từ tối ưu (Word Clouds Revisited)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đám mây từ tối ưu (Word Clouds Revisited)
Word Clouds Revisited
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A page has width . You must place word blocks in the given order. Block has width and height .
Each line contains a consecutive group of blocks whose total width is at most . The height of a line is the maximum height of a block on that line. Each block appears on exactly one line, and the block order must remain unchanged.
Minimize the sum of the line heights.
Input
The first line contains and , the number of blocks and page width.
Each of the next lines contains and , the width and height of block .
Output
Print the minimum possible sum of line heights.
Subtasks
- Subtask 1 (20 points): ; ; ; ; for all .
- Subtask 2 (30 points): ; ; ; ; for all .
- Subtask 3 (50 points): ; ; ; ; for all .
Examples
Input
6 260
65 23
38 11
135 48
97 43
95 28
130 23
Output
99
Explanation
Place blocks , , and on three consecutive lines. Each line fits the width limit . Their heights are , , and , giving , which is minimal.