This page is still under construction.

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

Buffed Buffet

Time limit4sMemory limit128 MB

Summary
Fill a plate of weight exactly w from discrete pieces and divisible dishes with linearly fading tastiness to maximize total tastiness.
Level

Hard8 of 10

Topics
Dynamic programming, Binary search, Math, Greedy
Solved
No attempts yet

Problem

You are buying lunch at a buffet. Several dishes are available, and you can mix them freely. Some dishes, such as dumplings or roasted potatoes, come in pieces of roughly equal size. You may take an integral number of such pieces. Call these discrete dishes. Other dishes, such as tzatziki or mashed potatoes, are fluid and you may take any real-valued amount. Call these continuous dishes.

You like some dishes more than others, but how much you enjoy a dish also depends on how much of it you have already eaten. Dish ii has an initial tastiness tit_i and a decay rate Δti\Delta t_i. For a discrete dish, the nn-th piece tastes like ti−(n−1)Δtit_i - (n-1)\Delta t_i. For a continuous dish, after you have already eaten xx grams, an additional dxdx grams tastes like (ti−xΔti) dx(t_i - x\Delta t_i)\,dx. The total tastiness from NN pieces of a discrete dish or XX grams of a continuous dish is

∑n=1N(ti−(n−1)Δti),∫0X(ti−xΔti) dx\sum_{n=1}^{N} (t_i - (n-1)\Delta t_i), \quad \int_0^X (t_i - x\Delta t_i)\,dx

Ignore pairing effects. The total tastiness of a meal is the sum of the tastinesses of its dishes, and the same rule applies to weight.

You already know every tit_i and Δti\Delta t_i. Compute the maximum total tastiness of a meal with weight exactly ww grams.

Input

A single test case is given.

  • Line 1: integers dd and ww (1≤d≤2501 \le d \le 250, 1≤w≤100001 \le w \le 10000), the number of dishes and the target meal weight in grams
  • Next dd lines: one line per dish
    • D $w_i$ $t_i$ $\Delta t_i$: a discrete dish whose pieces weigh wiw_i grams
    • C $t_i$ $\Delta t_i$: a continuous dish

All of wiw_i, tit_i, and Δti\Delta t_i are integers with 1≤wi≤100001 \le w_i \le 10000 and 0≤ti,Δti≤100000 \le t_i, \Delta t_i \le 10000.

Output

Print the maximum possible total tastiness of a meal with weight exactly ww. Your answer must have absolute or relative error at most 10−610^{-6}. If no meal has weight exactly ww, print impossible.

Examples3

  1. Example 1

    Input
    2 15
    D 4 10 1
    C 6 1
    
    Expected output
    40.500000000
    
  2. Example 2

    Input
    1 3
    D 4 10 1
    
    Expected output
    impossible
    
  3. Example 3

    Input
    1 8
    D 4 10 1
    
    Expected output
    19.000000000