QOJ.ac

QOJ

時間限制: 4 s 記憶體限制: 2048 MB 總分: 100

#7666. 自助餐大作战

统计

你在自助餐厅购买午餐。餐厅提供多种不同的菜肴,你可以随心所欲地搭配。有些菜肴(如饺子和烤土豆)由大小大致相等的块组成,你可以选择整数个这样的块(不允许分割)。我们将这类菜肴称为“离散菜肴”。其他菜肴(如蘸酱或土豆泥)是流体状的,你可以选择任意实数重量的菜肴。我们将这类菜肴称为“连续菜肴”。

当然,你对某些菜肴的喜爱程度高于其他菜肴,但你对一道菜的喜爱程度也取决于你已经吃了多少。例如,即使你通常更喜欢饺子而不是土豆,但如果你已经吃了十个饺子,你可能会更喜欢土豆。为了模拟这一点,每道菜 $i$ 都有一个初始美味度 $t_i$ 和一个美味度衰减率 $\Delta t_i$。对于离散菜肴,你吃第 $n$ 个该菜肴时感受到的美味度为 $t_i - (n - 1)\Delta t_i$。对于连续菜肴,在你已经吃了 $x$ 克该菜肴后,再吃无穷小量 $dx$ 克时感受到的美味度为 $(t_i - x\Delta t_i)dx$。换句话说,当你吃 $N$ 个离散菜肴或 $X$ 克连续菜肴时,你感受到的总美味度分别为:

$$\sum_{n=1}^{N} (t_i - (n - 1)\Delta t_i) \quad \text{和} \quad \int_{0}^{X} (t_i - x\Delta t_i)dx$$

为简化起见,不考虑不同菜肴搭配在一起是否合适,因此将你从一顿饭中感受到的总美味度定义为餐中各道菜总美味度之和(餐的总重量也一样——自助餐里没有食物反物质!)。

你已经花费数天时间进行了详尽的研究,确定了自助餐中每道菜的 $t_i$ 和 $\Delta t_i$。现在剩下的工作就是计算重量为 $w$ 的餐点所能达到的最大总美味度。快点,午餐马上就要开始了!

输入格式

输入包含一组测试数据。第一行包含两个整数 $d$ 和 $w$ ($1 \le d \le 250$ 且 $1 \le w \le 10\,000$),其中 $d$ 是自助餐中不同菜肴的数量,$w$ 是你想要的餐点总重量(单位为克)。

接下来有 $d$ 行,第 $i$ 行描述第 $i$ 道菜。每道菜的描述采用以下两种形式之一:

  • 形式为 “D $w_i$ $t_i$ $\Delta t_i$” 的描述表示这是一道离散菜肴,每份重量为 $w_i$ 克,初始美味度为 $t_i$,美味度衰减率为 $\Delta t_i$。
  • 形式为 “C $t_i$ $\Delta t_i$” 的描述表示这是一道连续菜肴,初始美味度为 $t_i$,美味度衰减率为 $\Delta t_i$。

数值 $w_i, t_i, \Delta t_i$ 均为整数,满足 $1 \le w_i \le 10\,000$ 且 $0 \le t_i, \Delta t_i \le 10\,000$。

输出格式

输出基于现有菜肴,重量为 $w$ 的餐点所能达到的最大总美味度。答案的相对误差或绝对误差应不超过 $10^{-6}$。如果无法根据现有菜肴配出总重量恰好为 $w$ 的餐点,则输出 impossible

样例

样例输入 1

2 15
D 4 10 1
C 6 1

样例输出 1

40.500000000

样例输入 2

3 15
D 4 10 1
C 6 1
C 9 3

样例输出 2

49.000000000

样例输入 3

2 19
D 4 5 1
D 6 3 2

样例输出 3

impossible

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.