Artist
InterviewTime limit1sMemory limit512 MB
Choose exactly K blocks from N to minimize (sum of chosen widths) times (sum of chosen heights), where each block keeps its orientation.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Greedy, Math
- Solved
- No attempts yet
Problem
Seungwon, better known by the pen name 'Nam Nam Seo', is an artist famous all over the world. Nobody else works the way he does, and every exhibition he opens fills up until there is no room left to stand.
Right now there are blocks in Seungwon's studio. He will pick exactly of them and build a new piece. He glues the chosen blocks from the lower left to the upper right so that they touch corner to corner, and he mounts the result on a canvas that fits it exactly.
A perfect piece matters a great deal to Seungwon, so he places every block parallel to the edges of the canvas, and he never swaps a block's width and height. That is, if the chosen blocks have widths and heights (, ), (, ), , (, ), the canvas he needs has size () ().
Seungwon wants the area of the canvas to be as small as possible. His art may be beyond us, but computing the minimum area of the canvas is not. Help him finish the piece.
Input
The first line contains the number of blocks Seungwon owns, (), and the number of blocks he will use, (), separated by a space.
Each of the next lines contains the width and the height of one block, separated by a space. (, , and the sum of all and the sum of all are each at most .)
Output
Print the minimum area of the canvas on the first line.