QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#10483. Mixing Solutions

統計

让我们准备进行一项关于化学物质“横滨黄”(Yokohama Yellow,简称 YY)的实验。你拥有若干装有 YY 水溶液的容器。虽然 YY 在每种溶液中均匀溶解,但不同容器中的浓度可能有所不同。你将从某些容器中取出任意量的溶液,并将它们混合,以制备出预定总量的混合溶液。

理想情况下,混合溶液应包含目标量的 YY,但存在一个问题。虽然已知每个容器中溶液的确切总量,但每种溶液中 YY 的含量仅能保证落在某个范围内。由于这种不确定性,很难使混合溶液中 YY 的含量完全等于目标量。不过,你可以确保误差(即与目标量之差)永远不会超过某个限度。

更准确地说,设混合溶液中 YY 的目标量为 $y_t$ mg(毫克),实际量为 $y_a$ mg。给定从各容器中取出的溶液量,可以保证 $y_a$ 落在某个范围内。最大误差定义为当 $y_a$ 在此范围内变化时, $|y_a - y_t|$ 的最大值。

在满足从各容器取出的溶液总量等于预定总量的前提下,求出最大误差的最小可能值。

输入格式

输入包含单个测试用例,格式如下:

$n$ $s$ $c$ $a_1$ $l_1$ $r_1$ $\vdots$ $a_n$ $l_n$ $r_n$

第一行包含三个整数 $n$、$s$ 和 $c$,满足 $1 \le n \le 1000$,$1 \le s \le 10^5$ 以及 $0 \le c \le M$,其中 $M = 10^4$(此处及下文均适用)。这里,$n$ 表示 YY 溶液容器的数量。混合溶液的预定总量为 $s$ mg,YY 的目标量为 $\frac{c}{M} s$ mg。

接下来的 $n$ 行中,第 $i$ 行包含三个整数 $a_i$、$l_i$ 和 $r_i$,满足 $1 \le a_i \le 10^5$ 以及 $0 \le l_i \le r_i \le M$。这些整数表示第 $i$ 个容器中有 $a_i$ mg 溶液,且其中 YY 的含量保证在 $\frac{l_i}{M} a_i$ mg 到 $\frac{r_i}{M} a_i$ mg(含边界)之间。满足 $\sum_{i=1}^n a_i \ge s$。

输出格式

可以证明最大误差的最小可能值是一个有理数。将该值表示为最简分数 $p/q$(其中 $q > 0$),并在单行中输出 $p$ 和 $q$,中间用空格分隔。

样例

样例输入 1

3 10 5000
10 2000 3000
10 4000 6000
10 7000 8000

样例输出 1

1 2

样例输入 2

2 10 5000
7 4500 5500
12 3500 6000

样例输出 2

4 5

样例输入 3

3 1 4159
1 1 1
1 100 100
1 10000 10000

样例输出 3

0 1

样例输入 4

6 12345 6789
2718 2818 2845
9045 2353 6028
7471 3526 6249
7757 2470 9369
9959 5749 6696
7627 7240 7663

样例输出 4

23901191037 67820000

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.