QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 512 MB Total points: 100

#8844. 鲜花

Statistics

我们种植了 $N$ 颗花种,它们最终会开出不同的花。我们希望让所有的花同时开放。

每株植物都有一个初始值为零的“活力值”。浇水和施肥会改变这个值,当第 $i$ 株植物的活力值大于或等于 $th_i$ 时,它就会开花。注意 $th_i$ 可能是负数,因为有些花不需要额外的营养。

浇水会影响所有的植物。用 $W$ 升水浇灌植物会使第 $i$ 株植物的活力值改变 $W \times vw_i$(对于所有 $1 \le i \le n$),并花费 $W \times pw$ 日元,其中 $W$ 不一定为整数。$vw_i$ 可能是负数,因为有些花不喜欢水。

我们有 $N$ 种肥料,第 $i$ 种肥料仅对第 $i$ 株植物有效。施用 $F_i$ 千克第 $i$ 种肥料会使第 $i$ 株植物的活力值改变 $F_i \times vf_i$,并花费 $F_i \times pf_i$ 日元,其中 $F_i$ 也不一定为整数。每种肥料都是专门为对应的植物制造的,因此保证 $vf_i$ 为正数。

当然,我们还希望最小化成本。形式上,我们的目标是“在满足 $W \times vw_i + F_i \times vf_i \ge th_i$,$W \ge 0$ 以及对于所有 $1 \le i \le N$ 都有 $F_i \ge 0$ 的条件下,最小化 $W \times pw + \sum_{i=1}^{N}(F_i \times pf_i)$”。你的任务是计算这个最小成本。

输入格式

输入包含多组数据。数据集的数量不超过 100,输入数据大小不超过 20MB。

每个数据集的第一行包含一个整数 $N$,表示花种的数量。第二行包含一个整数 $pw$,表示浇水一升的成本。接下来的 $N$ 行描述每一朵花。第 $i$ 行包含四个整数 $vw_i, pf_i, vf_i$ 和 $th_i$,以空格分隔。

你可以假设 $1 \le N \le 10^5$,$1 \le pw \le 100$,$-100 \le vw_i \le 100$,$1 \le pf_i \le 100$,$1 \le vf_i \le 100$,以及 $-100 \le th_i \le 100$。

输入以一行包含一个零作为结束。

输出格式

对于每个数据集,输出一行,包含使所有花开放的最小成本。输出的绝对误差或相对误差应不超过 $10^{-4}$。

样例

样例输入 1

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

样例输出 1

43.5
36
13.5
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.