CF1879F.Last Man Standing

省选/NOI-

通过率:0%

时间限制:7.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are nn heroes in a videogame. Each hero has some health value hh and initial armor value aa. Let the current value of armor be acura_{\mathit{cur}}, initially equal to aa.

When xx points of damage are inflicted on a hero, the following happens: if x<acurx \lt a_{\mathit{cur}}, then xx gets subtracted from acura_{\mathit{cur}}; otherwise, 11 gets subtracted from hh and acura_{\mathit{cur}} gets assigned back to aa.

In the start of the game, you choose the value xx (an integer strictly greater than 00, arbitrarily large). Then you keep attacking all heroes in rounds: in one round, you inflict xx points of damage to all alive heroes. A hero dies when his health becomes 00. The game ends when all heroes are dead.

The last hero to die earns the number of points, equal to the number of rounds he was the only hero alive. The other heroes get 00 points. In particular, if the last round ends with multiple heroes dying, then every hero gets 00 points.

The game is played for every possible xx (from 11 to infinity). The points are reset between the games. What's the maximum number of points each hero has had?

游戏中有 nn 位英雄。每位英雄具有一个生命值 hh 和一个初始护甲值 aa。令当前护甲值为 acura_{\mathit{cur}},其初始值等于 aa。

当对某位英雄造成 xx 点伤害时,发生如下过程:若 x<acurx \lt a_{\mathit{cur}},则从 acura_{\mathit{cur}} 中减去 xx;否则,该英雄的生命值 hh 减少 11,且 acura_{\mathit{cur}} 被重置为 aa。

游戏开始时,你需要选定一个值 xx(xx 为严格大于 00 的整数,可任意大)。随后你按轮次持续攻击所有存活的英雄:每轮中,你对所有当前存活的英雄各造成 xx 点伤害。当一位英雄的生命值变为 00 时,他即死亡。当所有英雄均死亡时,游戏结束。

最后一位死亡的英雄获得积分,积分数值等于他在整场游戏中“唯一存活的英雄”所持续的轮数。其余英雄获得 00 积分。特别地,若最后一轮中有多个英雄同时死亡,则所有英雄均获得 00 积分。

游戏将对每个可能的 xx 值(从 11 到无穷大)分别进行。不同 xx 值对应的游戏之间积分相互独立、互不干扰。问:每位英雄在其所有游戏中曾获得过的最高积分是多少?

输入格式

The first line contains a single integer tt (1≤t≤101 \le t \le 10) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of heroes.

The second line contains nn integers h1,h2,…,hnh_1, h_2, \dots, h_n (1≤hi≤2⋅1051 \le h_i \le 2 \cdot 10^5) — the health value of each hero.

The third line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5) — the initial armor value of each hero.

第一行包含一个整数 tt(1≤t≤101 \le t \le 10)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 英雄的数量。

第二行包含 nn 个整数 h1,h2,…,hnh_1, h_2, \dots, h_n(1≤hi≤2⋅1051 \le h_i \le 2 \cdot 10^5)—— 每位英雄的生命值。

第三行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5)—— 每位英雄的初始护甲值。

输出格式

For each testcase, print nn integers — the maximum number of points each hero has had over the games played for every possible xx.

对于每个测试用例,输出 nn 个整数——即对每个可能的 xx,每位英雄在已进行的游戏中所获得的最大分数。

输入输出样例

  • 输入#1

    3
    3
    3 1 2
    3 11 5
    1
    100
    200
    4
    5 9 5 1
    9 2 9 10

    输出#1

    1 1 1 
    20000 
    0 4 0 0

说明/提示

In the first testcase, the game for x=1x = 1 is played as follows:

  • before all rounds: the heroes have h=[3,1,2]h = [3, 1, 2], acur=[3,11,5]a_{\mathit{cur}} = [3, 11, 5];
  • round 11: 11 damage is inflicted on every hero: hh remains [3,1,2][3, 1, 2], acura_{\mathit{cur}} becomes [2,10,4][2, 10, 4];
  • round 22: h=[3,1,2]h = [3, 1, 2], acur=[1,9,3]a_{\mathit{cur}} = [1, 9, 3];
  • round 33: the first hero runs out of armor, so he loses a health point: h=[2,1,2]h = [2, 1, 2], acur=[3,8,2]a_{\mathit{cur}} = [3, 8, 2];
  • ...
  • round 99: the first hero dies, since his health reaches 00: h=[0,1,1]h = [0, 1, 1], acur=[0,2,1]a_{\mathit{cur}} = [0, 2, 1];
  • round 1010: the third hero dies: h=[0,1,0]h = [0, 1, 0], acur=[0,1,0]a_{\mathit{cur}} = [0, 1, 0];
  • round 1111: the second hero dies: h=[0,0,0]h = [0, 0, 0], acur=[0,0,0]a_{\mathit{cur}} = [0, 0, 0].

The second hero was the last hero to die, and he was the only hero alive during one round. Thus, he gets 11 point for that game.

The game for x=4x = 4 is played as follows:

  • round 11: h=[2,1,2]h = [2, 1, 2], acur=[3,7,1]a_{\mathit{cur}} = [3, 7, 1];
  • round 22: h=[1,1,1]h = [1, 1, 1], acur=[3,3,5]a_{\mathit{cur}} = [3, 3, 5];
  • round 33: h=[0,0,1]h = [0, 0, 1], acur=[0,0,1]a_{\mathit{cur}} = [0, 0, 1];
  • round 44: h=[0,0,0]h = [0, 0, 0], acur=[0,0,0]a_{\mathit{cur}} = [0, 0, 0];

The third hero was the last hero to die, and he was the only hero alive during one round.

在第一个测试用例中,当 x=1x = 1 时的游戏过程如下:

  • 所有轮次开始前:英雄的生命值为 h=[3,1,2]h = [3, 1, 2],当前护甲值为 acur=[3,11,5]a_{\mathit{cur}} = [3, 11, 5];
  • 第 11 轮:每位英雄受到 11 点伤害:hh 仍为 [3,1,2][3, 1, 2],acura_{\mathit{cur}} 变为 [2,10,4][2, 10, 4];
  • 第 22 轮:h=[3,1,2]h = [3, 1, 2],acur=[1,9,3]a_{\mathit{cur}} = [1, 9, 3];
  • 第 33 轮:第一位英雄护甲耗尽,因此损失 11 点生命值:h=[2,1,2]h = [2, 1, 2],acur=[3,8,2]a_{\mathit{cur}} = [3, 8, 2];
  • …
  • 第 99 轮:第一位英雄死亡(生命值降为 00):h=[0,1,1]h = [0, 1, 1],acur=[0,2,1]a_{\mathit{cur}} = [0, 2, 1];
  • 第 1010 轮:第三位英雄死亡:h=[0,1,0]h = [0, 1, 0],acur=[0,1,0]a_{\mathit{cur}} = [0, 1, 0];
  • 第 1111 轮:第二位英雄死亡:h=[0,0,0]h = [0, 0, 0],acur=[0,0,0]a_{\mathit{cur}} = [0, 0, 0]。

第二位英雄是最后一位死亡的英雄,且他在某一轮中是场上唯一存活的英雄。因此,他在该局游戏中获得 11 分。

当 x=4x = 4 时的游戏过程如下:

  • 第 11 轮:h=[2,1,2]h = [2, 1, 2],acur=[3,7,1]a_{\mathit{cur}} = [3, 7, 1];
  • 第 22 轮:h=[1,1,1]h = [1, 1, 1],acur=[3,3,5]a_{\mathit{cur}} = [3, 3, 5];
  • 第 33 轮:h=[0,0,1]h = [0, 0, 1],acur=[0,0,1]a_{\mathit{cur}} = [0, 0, 1];
  • 第 44 轮:h=[0,0,0]h = [0, 0, 0],acur=[0,0,0]a_{\mathit{cur}} = [0, 0, 0];

第三位英雄是最后一位死亡的英雄,且他在某一轮中是场上唯一存活的英雄。

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

首页