Cheese Towers
Time limit1sMemory limit128 MB
Stack unlimited cheese blocks up to total height T; any block of height at least K crushes everything below it to 4/5 height, maximizing total value.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Math
- Solved
- No attempts yet
Problem
You want to store blocks of cheese as a single tower whose total height is at most ().
There are () types of cheese, numbered through , and you have an unlimited supply of blocks of every type. A block of type has value () and height (), where every is a multiple of .
Cheese compresses. A block whose height is at least () is called large. A large block crushes every block located below it in the tower, including other large blocks. A crushed block keeps its full value, but its height shrinks to exactly of its original height. Because every height is a multiple of , a crushed height is always an integer. Crushing is all-or-nothing: a block is either crushed or not, and having several large blocks above it does not crush it any further. Whether a block is large depends only on that block's own height, never on the overall height of the tower.
Build a tower of total height at most that maximizes the sum of the values of its blocks, and output that maximum total value.
For example, suppose the tower may be at most tall, a block is large when its height is at least , and there are three types of cheese:
Type Value Height
1 100 25
2 20 5
3 40 10
One possible tower is:
Type Height Value
top -> [1] 25 100
[2] 4 20 (crushed by [1] above)
[3] 8 40 (crushed by [1] above)
[3] 8 40 (crushed by [1] above)
bottom -> [3] 8 40 (crushed by [1] above)
The large block on top crushes every block beneath it. The total height is , so the tower is legal, and the total value is . This is the best tower for this set of blocks.
Input
- Line : three space-separated integers , , and .
- Lines through : line contains two space-separated integers and .
Output
- One line: the maximum total value of a tower you can build.