Buffed Buffet
Time limit4sMemory limit128 MB
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 has an initial tastiness and a decay rate . For a discrete dish, the -th piece tastes like . For a continuous dish, after you have already eaten grams, an additional grams tastes like . The total tastiness from pieces of a discrete dish or grams of a continuous dish is
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 and . Compute the maximum total tastiness of a meal with weight exactly grams.
Input
A single test case is given.
- Line 1: integers and (, ), the number of dishes and the target meal weight in grams
- Next lines: one line per dish
D $w_i$ $t_i$ $\Delta t_i$: a discrete dish whose pieces weigh gramsC $t_i$ $\Delta t_i$: a continuous dish
All of , , and are integers with and .
Output
Print the maximum possible total tastiness of a meal with weight exactly . Your answer must have absolute or relative error at most . If no meal has weight exactly , print impossible.