AT_abc458_g.Children Yearn for the Evil Kindergarten

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are 1010010^{100} kids at a game venue. Initially, no kid has any medals.

A kid leaves the venue exactly when they either drop out or escape.

The game consists of NN days. On day ii (1≤i≤N1 \leq i \leq N), the following sequence of operations is performed in order.

  • Collect all medals held by the kids at the venue, and let ss be the total number of collected medals.
  • Distribute s+Ais + A_i medals freely among the kids at the venue (if there are no kids at the venue, do nothing).
  • Among the kids at the venue, those with fewer than BiB_i medals drop out. Those with at least BiB_i medals each lose BiB_i medals.
  • Among the kids at the venue, those with at least CiC_i medals each choose whether to escape at this point or remain at the venue.

Kids who remain at the venue at the end of the NN days drop out.

Find the maximum possible number of kids who ultimately escape.

You are given TT test cases; solve each of them.

游戏场地中有 1010010^{100} 个孩子。初始时,没有任何孩子拥有奖牌。

一个孩子恰好在以下两种情形之一发生时离开场地:退出或逃离。

游戏共持续 NN 天。在第 ii 天(1≤i≤N1 \leq i \leq N),按顺序执行如下操作:

  • 收集所有仍在场地内的孩子所持有的奖牌,记收集到的奖牌总数为 ss;
  • 将 s+Ais + A_i 枚奖牌自由地分发给仍在场地内的孩子(若此时场内没有孩子,则不进行任何操作);
  • 在仍在场地内的孩子中,持有少于 BiB_i 枚奖牌者退出;持有至少 BiB_i 枚奖牌者每人失去 BiB_i 枚奖牌;
  • 在仍在场地内的孩子中,持有至少 CiC_i 枚奖牌者每人可选择此时逃离场地,或继续留在场地内。

在 NN 天结束时仍留在场地内的孩子将退出。

求最终能够逃离场地的孩子数量的最大可能值。

你将得到 TT 组测试数据,请对每组数据分别求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_{1}
case2\mathrm{case}_{2}
⋮\vdots
caseT\mathrm{case}_{T}

Each test case is given in the following format:

NN
A1A_1 B1B_1 C1C_1
A2A_2 B2B_2 C2C_2
⋮\vdots
ANA_N BNB_N CNC_N

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_{1}
case2\mathrm{case}_{2}
⋮\vdots
caseT\mathrm{case}_{T}

每个测试用例按以下格式给出:

NN
A1A_1 B1B_1 C1C_1
A2A_2 B2B_2 C2C_2
⋮\vdots
ANA_N BNB_N CNC_N

输出格式

Output the answers for the test cases in order, separated by newlines.

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    2
    4
    16 2 3
    15 2 4
    1 3 5
    20 5 5
    2
    41404 1 941738
    211877 205711 417821

    输出#1

    5
    0

说明/提示

Sample 1 Explanation:
Consider the first test case. By acting as follows, five kids can escape.

  • At the start of day 11, collect s=0s = 0 medals from 1010010^{100} kids. Then, proceed as follows.
    • Distribute 0+16=160 + 16 = 16 medals so that the kids' medal counts become (5,5,2,2,2,0,…,0)(5, 5, 2, 2, 2, 0, \dots, 0).
    • The 10100−510^{100} - 5 kids with no medals drop out, and the remaining 55 kids' medal counts become (3,3,0,0,0)(3, 3, 0, 0, 0).
    • The 22 kids with 33 medals each choose to escape, and the remaining 33 kids' medal counts become (0,0,0)(0, 0, 0).
  • At the start of day 22, collect s=0s = 0 medals from 33 kids. Then, proceed as follows.
    • Distribute 0+15=150 + 15 = 15 medals so that the kids' medal counts becomes (6,6,3)(6, 6, 3).
    • No one drops out, and the remaining 33 kids' medal counts become (4,4,1)(4, 4, 1).
    • 11 kid with 44 medals chooses to escape, and the remaining 22 kids' medal counts become (4,1)(4, 1).
  • At the start of day 33, collect s=5s = 5 medals from 22 kids. Then, proceed as follows.
    • Distribute 5+1=65 + 1 = 6 medals so that the kids' medal counts becomes (3,3)(3, 3).
    • No one drops out, and the remaining 22 kids' medal counts become (0,0)(0, 0).
    • No one escapes.
  • At the start of day 44, collect s=0s = 0 medals from 22 kids. Then, proceed as follows.
    • Distribute 0+20=200 + 20 = 20 medals so that the kids' medal counts becomes (10,10)(10, 10).
    • No one drops out, and the remaining 22 kids' medal counts become (5,5)(5, 5).
    • The 22 kids with 55 medals each choose to escape, and the venue becomes empty.

In the second test case, not a single kid can escape.

Constraints

  • 1≤T≤3×1051 \leq T \leq 3 \times 10^5
  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 1≤Ai≤1061 \leq A_i \leq 10^6
  • 1≤Bi≤1061 \leq B_i \leq 10^6
  • 1≤Ci≤1061 \leq C_i \leq 10^6
  • The sum of NN over all test cases is at most 3×1053 \times 10^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。通过如下操作,可使五名儿童成功逃脱。

  • 第 1 天开始时,从 1010010^{100} 名儿童处收集 s=0s = 0 枚奖牌。随后执行以下步骤:
    • 分发 0+16=160 + 16 = 16 枚奖牌,使得儿童的奖牌数变为 (5,5,2,2,2,0,…,0)(5, 5, 2, 2, 2, 0, \dots, 0)。
    • 没有获得奖牌的 10100−510^{100} - 5 名儿童退出,剩余 55 名儿童的奖牌数变为 (3,3,0,0,0)(3, 3, 0, 0, 0)。
    • 两名拥有 33 枚奖牌的儿童选择逃脱,剩余 33 名儿童的奖牌数变为 (0,0,0)(0, 0, 0)。
  • 第 2 天开始时,从 33 名儿童处收集 s=0s = 0 枚奖牌。随后执行以下步骤:
    • 分发 0+15=150 + 15 = 15 枚奖牌,使得儿童的奖牌数变为 (6,6,3)(6, 6, 3)。
    • 无人退出,剩余 33 名儿童的奖牌数变为 (4,4,1)(4, 4, 1)。
    • 一名拥有 44 枚奖牌的儿童选择逃脱,剩余 22 名儿童的奖牌数变为 (4,1)(4, 1)。
  • 第 3 天开始时,从 22 名儿童处收集 s=5s = 5 枚奖牌。随后执行以下步骤:
    • 分发 5+1=65 + 1 = 6 枚奖牌,使得儿童的奖牌数变为 (3,3)(3, 3)。
    • 无人退出,剩余 22 名儿童的奖牌数变为 (0,0)(0, 0)。
    • 无人逃脱。
  • 第 4 天开始时,从 22 名儿童处收集 s=0s = 0 枚奖牌。随后执行以下步骤:
    • 分发 0+20=200 + 20 = 20 枚奖牌,使得儿童的奖牌数变为 (10,10)(10, 10)。
    • 无人退出,剩余 22 名儿童的奖牌数变为 (5,5)(5, 5)。
    • 两名拥有 55 枚奖牌的儿童选择逃脱,场地清空。

在第二个测试用例中,没有任何一名儿童能够逃脱。

约束条件

  • 1≤T≤3×1051 \leq T \leq 3 \times 10^5
  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 1≤Ai≤1061 \leq A_i \leq 10^6
  • 1≤Bi≤1061 \leq B_i \leq 10^6
  • 1≤Ci≤1061 \leq C_i \leq 10^6
  • 所有测试用例的 NN 之和不超过 3×1053 \times 10^5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页