#icpc2014autumnd. [icpc2014autumn_d]Flowers
[icpc2014autumn_d]Flowers
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
We have planted flower seeds, all of which come into different flowers. We want to make all the flowers come out together.
Each plant has a value called vitality, which is initially zero. Watering and spreading fertilizers cause changes on it, and the -th plant will come into flower if its vitality is equal to or greater than . Note that may be negative because some flowers require no additional nutrition.
Watering effects on all the plants. Watering the plants with liters of water changes the vitality of the -th plant by for all (), and costs yen, where need not be an integer. may be negative because some flowers hate water.
We have kinds of fertilizers, and the -th fertilizer effects only on the -th plant. Spreading kilograms of the -th fertilizer changes the vitality of the -th plant by , and costs yen, where need not be an integer as well. Each fertilizer is specially made for the corresponding plant, therefore is guaranteed to be positive.
Of course, we also want to minimize the cost. Formally, our purpose is described as "to minimize $W \\times \\mathit{pw} + \\sum\_{i=1}^{N}(F\_i \\times \\mathit{pf}\_i)$ under $W \\times \\mathit{vw}\_i + F\_i \\times \\mathit{vf}\_i \\ge \\mathit{th}\_i$, , and for all ()". Your task is to calculate the minimum cost.
Input
The input consists of multiple datasets. The number of datasets does not exceed , and the data size of the input does not exceed . Each dataset is formatted as follows.
:
:
The first line of a dataset contains a single integer , number of flower seeds. The second line of a dataset contains a single integer , cost of watering one liter. Each of the following lines describes a flower. The -th line contains four integers, , , , and , separated by a space.
You can assume that , , , , , and .
The end of the input is indicated by a line containing a zero.
Output
For each dataset, output a line containing the minimum cost to make all the flowers come out. The output must have an absolute or relative error at most .
Sample 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```
### Output for the Sample Input
```plain
43.5
36
13.5
0```
* * *
### Source Name
JAG Practice Contest for ACM-ICPC Asia Regional 2014
* * *