This page is still under construction.

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

Flowers

Time limit8sMemory limit512 MB

Summary
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.
Level

Medium7 of 10

Topics
Math, Greedy, Geometry
Solved
No attempts yet

Problem

We planted NN 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 ii blooms once its vitality is at least thith_i. Some flowers need no extra nutrition, so thith_i can be negative.

Water reaches every plant. Pouring WW liters of water changes the vitality of plant ii by W×vwiW \times vw_i for every ii (1≤i≤N1 \le i \le N) and costs W×pwW \times pw yen. WW does not have to be an integer. Some flowers hate water, so vwivw_i can be negative.

There are NN kinds of fertilizer, and the ii-th kind works only on plant ii. Spreading FiF_i kilograms of the ii-th fertilizer changes the vitality of plant ii by Fi×vfiF_i \times vf_i and costs Fi×pfiF_i \times pf_i yen. FiF_i does not have to be an integer either. Each fertilizer is made for its own plant, so vfivf_i is always positive.

Of course we also want to keep the total cost as small as possible. Formally, minimize

W×pw+∑i=1NFi×pfiW \times pw + \sum_{i=1}^{N} F_i \times pf_i

subject to W×vwi+Fi×vfi≥thiW \times vw_i + F_i \times vf_i \ge th_i, W≥0W \ge 0 and Fi≥0F_i \ge 0 for every ii (1≤i≤N1 \le i \le N). 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 NN. The second line holds pwpw, the price of one liter of water. Each of the next NN lines describes one flower with four integers vwivw_i, pfipf_i, vfivf_i and thith_i, separated by a space.

Every value satisfies 1≤N≤1000001 \le N \le 100000, 1≤pw≤1001 \le pw \le 100, −100≤vwi≤100-100 \le vw_i \le 100, 1≤pfi≤1001 \le pf_i \le 100, 1≤vfi≤1001 \le vf_i \le 100 and −100≤thi≤100-100 \le th_i \le 100.

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.

Examples3

  1. Example 1

    Input
    3
    10
    4 3 4 10
    5 4 5 20
    6 5 6 30
    3
    7
    -4 3 4 -10
    5 4 5 20
    6 5 6 30
    3
    1
    -4 3 4 -10
    -5 4 5 -20
    6 5 6 30
    3
    10
    -4 3 4 -10
    -5 4 5 -20
    -6 5 6 -30
    0
    
    Expected output
    43.500000
    36.000000
    13.500000
    0.000000
    
  2. Example 2

    Input
    1
    1
    1 100 1 100
    0
    
    Expected output
    100.000000
    
  3. Example 3

    Input
    1
    1
    -1 3 4 100
    0
    
    Expected output
    75.000000