This page is still under construction.

Parts of this page are still being built. What you see may change.

Cheese Towers

Time limit1sMemory limit128 MB

Summary
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 TT (1≤T≤10001 \le T \le 1000).

There are NN (1≤N≤1001 \le N \le 100) types of cheese, numbered 11 through NN, and you have an unlimited supply of blocks of every type. A block of type ii has value ViV_i (1≤Vi≤1061 \le V_i \le 10^6) and height HiH_i (5≤Hi≤T5 \le H_i \le T), where every HiH_i is a multiple of 55.

Cheese compresses. A block whose height is at least KK (1≤K≤T1 \le K \le T) 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 4/54/5 of its original height. Because every height is a multiple of 55, 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 TT 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 5353 tall, a block is large when its height is at least 2525, 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 25+4+8+8+8=53≤5325 + 4 + 8 + 8 + 8 = 53 \le 53, so the tower is legal, and the total value is 100+20+40+40+40=240100 + 20 + 40 + 40 + 40 = 240. This is the best tower for this set of blocks.

Input

  • Line 11: three space-separated integers NN, TT, and KK.
  • Lines 22 through N+1N+1: line i+1i+1 contains two space-separated integers ViV_i and HiH_i.

Output

  • One line: the maximum total value of a tower you can build.

Examples2

  1. Example 1

    Input
    3 53 25
    100 25
    20 5
    40 10
    
    Expected output
    240
    
  2. Example 2

    Input
    2 30 5
    10 5
    100 30
    
    Expected output
    110