luogu#P9124. [USACO23FEB] Bakery S

[USACO23FEB] Bakery S

题目描述

Bessie has opened a bakery!

In her bakery, Bessie has an oven that can produce a cookie in tCt_C units of time or a muffin in tMt_M units of time (1tC,tM109)(1\le t_C,t_M\le 10^9). Due to space constraints, Bessie can only produce one pastry at a time, so to produce AA cookies and BB muffins, it takes AtC+BtMA \cdot t_C+B \cdot t_M units of time.

Bessie's N(1N100)N (1\le N\le 100) friends would each like to visit the bakery one by one. The ii-th friend will order ai(1ai109)a_i(1 \le a_i \le 10^9) cookies and bi(1bi109)b_i(1 \le b_i \le 10^9) muffins immediately upon entering. Bessie doesn't have space to store pastries, so she only starts making pastries upon receiving an order. Furthermore, Bessie's friends are very busy, so the ii-th friend is only willing to wait ci(ai+bici21018)c_i(a_i+b_i \le c_i \le 2 \cdot 10^{18}) units of time before getting sad and leaving.

Bessie really does not want her friends to be sad. With one mooney, she can upgrade her oven so that it takes one less unit of time to produce a cookie or one less unit of time to produce a muffin. She can't upgrade her oven a fractional amount of times, but she can choose to upgrade her oven as many times as she needs before her friends arrive, as long as the time needed to produce a cookie and to produce a muffin both remain strictly positive.

For each of T(1T100)T(1 \le T \le 100) test cases, please help Bessie find out the minimum amount of moonies that Bessie must spend so that her bakery can satisfy all of her friends.

输入格式

The first line contains TT, the number of test cases.

Each test case starts with one line containing NN , tCt_C, tMt_M. Then, the next NN lines each contain three integers ai,bi,cia_i,b_i,c_i.

Consecutive test cases are separated by newlines.

输出格式

The minimum amount of moonies that Bessie needs to spend for each test case, on separate lines.

题目大意

题目描述

Bessie 开了一家面包店!

在她的面包店里,Bessie 有一个烤箱,可以在 tCt_C 的时间内生产一块饼干或在 tMt_M 单位时间内生产一块松糕。 (1tC,tM109)(1 \le t_C,t_M \le 10^9)。由于空间限制,Bessie 一次只能生产一种糕点,所以要生产 AA 块饼干和 BB 块松饼,需要 AtC+BtMA\cdot t_C+B\cdot t_M 单位的时间。

Bessie的 N(1N100)N (1\le N\le 100) 朋友都想一个一个地去面包店。第 ii 个朋友一进门就会点 ai(1ai109)a_i(1 \le a_i \le 10^9) 块饼干和 bi(1bi109)b_i(1 \le b_i \le 10^9) 块松饼。Bessie 没有空间来储存糕点,所以她只有在接到订单后才开始制作糕点。此外,Bessie 的朋友都很忙,所以第 ii 个朋友只愿意等 ci(ai+bici21018)c_i(a_i+b_i \le c_i \le 2 \cdot 10^{18}) 个单位的时间,然后就伤心地离开。

Bessie 真的不希望她的朋友们伤心,她可以用一块钱升级她的烤箱,让它少花一个单位的时间来生产一块饼干或少花一个单位的时间来生产一个松饼。她不能将她的烤箱升级到花费小于等于 00 的时间,但她可以选择在她的朋友到来之前将她的烤箱升级多少次,只要生产一块饼干和生产一个松饼所需的时间都严格保持为正数。

对于每一个 T(1T100)T(1\le T\le 100) 的测试案例,请帮助 Bessie 找出她必须花费的最小的钱数量,以便她的面包店能够满足所有的朋友。

输入格式

第一行包含 TT,测试案例的数量。

每个测试用例都以一行开始,包含 NN ,tCt_C,tMt_M。然后,接下来的 NN 行各包含三个整数 ai,bi,cia_i,b_i,c_i

测试案例用换行符隔开。

输出格式

Bessie 需要为每个测试案例花费的最少钱数,每行一个。

样例 #1

样例输入 #1

2

3 7 9
4 3 18
2 4 19
1 1 6

5 7 3
5 9 45
5 2 31
6 4 28
4 1 8
5 2 22

样例输出 #1

11
6

提示

样例解释 1

在第一个测试案例中,贝西可以支付 1111 元来减少 44 单位生产一块饼干所需的 时间和 77 单位生产一块松饼所需的时间,从而使她的烤箱在 33 单位的时间内生产饼干,在 22 单位的时间内生产松饼。那么她可以在 1818 单位的时间内满足第一个朋友,在 1414 单位的时间内满足第二个朋友,在 55 单位的时间内满足第三个朋友,所以他们都不会伤心而离开。

在第二个测试案例中,贝西应该把生产一块饼干的时间减少 66 单位,把生产一块松饼的时间减少 00 单位。

数据规模与约定

  • 输入 242-4N10,tC,tM1000N\le 10,t_C,t_M \le 1000
  • 输入 5115-11,没有额外的约束。

翻译 @ __11jiang08__

2

3 7 9
4 3 18
2 4 19
1 1 6

5 7 3
5 9 45
5 2 31
6 4 28
4 1 8
5 2 22
11
6

提示

Explanation for Sample 1

In the first test case, Bessie can pay 1111 moonies to decrease the time required to produce a cookie by 44 and a muffin by 77, so that her oven produces cookies in 33 units of time and muffins in 22 units of time. Then she can satisfy the first friend in 1818 units of time, the second friend in 1414 units of time, and the third friend in 55 units of time, so none of them will get sad and leave.

In the second test case, Bessie should decrease the time required to produce a cookie by 66 and a muffin by 00.

SCORING

  • Inputs 242-4: N10,tC,tM1000N \le 10,t_C,t_M \le 1000
  • Inputs 5115-11: No additional constraints.