Flowers
Time limit8sMemory limit512 MB
Minimize W*pw + sum F_i*pf_i subject to W*vw_i + F_i*vf_i >= th_i, with W,F_i >= 0 and reals allowed.
Problem
We planted flower seeds, and every seed grows into a different flower. We want all of them to bloom at the same time.
Every plant has a number called vitality, and it starts at 0. Watering and fertilizer change it, and plant blooms once its vitality is at least . Some flowers need no extra nutrition, so can be negative.
Water reaches every plant. Pouring liters of water changes the vitality of plant by for every () and costs yen. does not have to be an integer. Some flowers hate water, so can be negative.
There are kinds of fertilizer, and the -th kind works only on plant . Spreading kilograms of the -th fertilizer changes the vitality of plant by and costs yen. does not have to be an integer either. Each fertilizer is made for its own plant, so is always positive.
Of course we also want to keep the total cost as small as possible. Formally, minimize
subject to , and for every (). Compute that minimum cost.
Input
The input holds several datasets. There are at most 100 of them, and the whole input is at most 20MB. One dataset is formatted like this.
N
pw
vw1 pf1 vf1 th1
:
:
vwN pfN vfN thN
The first line holds the number of flower seeds . The second line holds , the price of one liter of water. Each of the next lines describes one flower with four integers , , and , separated by a space.
Every value satisfies , , , , and .
A line holding a single 0 marks the end of the input.
Output
For each dataset, print one line with the minimum cost that makes every flower bloom. Print the cost with exactly six digits after the decimal point, rounding the seventh digit and beyond half up.