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.
Medium7MathGreedyGeometryNo attempts yetTime limit8sMemory limit512 MBWe planted N 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 i blooms once its vitality is at least thi. Some flowers need no extra nutrition, so thi can be negative.
Water reaches every plant. Pouring W liters of water changes the vitality of plant i by W×vwi for every i (1≤i≤N) and costs W×pw yen. W does not have to be an integer. Some flowers hate water, so vwi can be negative.
There are N kinds of fertilizer, and the i-th kind works only on plant i. Spreading Fi kilograms of the i-th fertilizer changes the vitality of plant i by Fi×vfi and costs Fi×pfi yen. Fi does not have to be an integer either. Each fertilizer is made for its own plant, so vfi is always positive.
Of course we also want to keep the total cost as small as possible. Formally, minimize
W×pw+∑i=1NFi×pfi
subject to W×vwi+Fi×vfi≥thi, W≥0 and Fi≥0 for every i (1≤i≤N). Compute that minimum cost.
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 N. The second line holds pw, the price of one liter of water. Each of the next N lines describes one flower with four integers vwi, pfi, vfi and thi, separated by a space.
Every value satisfies 1≤N≤100000, 1≤pw≤100, −100≤vwi≤100, 1≤pfi≤100, 1≤vfi≤100 and −100≤thi≤100.
A line holding a single 0 marks the end of the input.
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.