CF1795C.Tea Tasting

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A tea manufacturer decided to conduct a massive tea tasting. nn sorts of tea will be tasted by nn tasters. Both the sorts of tea and the tasters are numbered from 11 to nn. The manufacturer prepared aia_i milliliters of the ii-th sort of tea. The jj-th taster can drink bjb_j milliliters of tea at once.

The tasting will be conducted in steps. During the first step, the ii-th taster tastes the ii-th sort of tea. The ii-th taster drinks min⁡(ai,bi)\min(a_i, b_i) tea (how much is available of the ii-th sort and how much the ii-th taster can drink). aia_i also decreases by this amount.

Then all tasters move to the previous sort of tea. Thus, during the second step, the ii-th taster tastes the (i−1)(i-1)-st sort of tea. The ii-th taster drinks min⁡(ai−1,bi)\min(a_{i-1}, b_i) tea. The 11-st person ends the tasting.

During the third step, the ii-th taster tastes the (i−2)(i-2)-nd sort of tea. The 22-nd taster ends the tasting. This goes on until everyone ends the tasting.

Take a look at the tasting process for n=3n = 3, a=[10,20,15]a = [10, 20, 15], b=[9,8,6]b = [9, 8, 6]. In the left row, there are the current amounts of each sort of tea. In the right column, there are current amounts of tea each taster has drunk in total. The arrow tells which taster each tea goes to on the current step. The number on the arrow is the amount — minimum of how much is available of the sort of tea and how much the taster can drink.

For each taster, print how many milliliters of tea he/she will drink in total.

一家茶叶制造商决定开展一场大规模的品茶活动。共有 nn 种茶叶,由 nn 位品茶师进行品尝。茶叶种类与品茶师均从 11 编号至 nn。制造商为第 ii 种茶叶准备了 aia_i 毫升;第 jj 位品茶师单次最多可饮用 bjb_j 毫升茶叶。

品茶活动分若干轮进行。第一轮中,第 ii 位品茶师品尝第 ii 种茶叶,饮用量为 min⁡(ai,bi)\min(a_i, b_i)(即第 ii 种茶叶当前剩余量与第 ii 位品茶师单次最大饮用量二者中的较小值),随后 aia_i 相应减少该饮用量。

此后,所有品茶师均转向品尝前一种茶叶(编号减 11)。因此,在第二轮中,第 ii 位品茶师品尝第 (i−1)(i-1) 种茶叶,饮用量为 min⁡(ai−1,bi)\min(a_{i-1}, b_i);第 11 位品茶师在此轮后结束品茶。

在第三轮中,第 ii 位品茶师品尝第 (i−2)(i-2) 种茶叶;第 22 位品茶师在此轮后结束品茶。以此类推,直至所有品茶师均完成品茶。

请参看 n=3n = 3、a=[10,20,15]a = [10, 20, 15]、b=[9,8,6]b = [9, 8, 6] 时的品茶过程示意图:左侧一列显示各茶叶当前剩余量,右侧一列显示各位品茶师截至目前累计饮用量。箭头表示本轮中某类茶叶供给哪位品茶师,箭头上所标数字即为实际饮用量——即该种茶叶当前剩余量与该品茶师单次最大饮用量二者之最小值。

对每位品茶师,请输出其最终累计饮用了多少毫升茶叶。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — 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 sorts of tea and the number of tasters.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the amount of each sort of tea.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤1091 \le b_i \le 10^9) — the amount of tea each taster can drink at once.

The sum of nn over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 茶的种类数与品茶师人数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 每种茶的量。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤1091 \le b_i \le 10^9)—— 每位品茶师单次可饮茶的量。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print nn integers — the ii-th value should be equal to the total amount of tea the ii-th taster will drink.

对于每个测试用例,输出 nn 个整数——其中第 ii 个值应等于第 ii 个品茶师将饮用的茶的总量。

输入输出样例

  • 输入#1

    4
    3
    10 20 15
    9 8 6
    1
    5
    7
    4
    13 8 5 4
    3 4 2 1
    3
    1000000000 1000000000 1000000000
    1 1 1000000000

    输出#1

    9 9 12 
    5 
    3 8 6 4 
    1 2 2999999997

说明/提示

The first testcase is described in the statement. Here are the remaining amounts of each sort of tea after each step and the total amount of tea each taster has drunk:

  • a=[1,12,9]a = [1, 12, 9], ans=[9,8,6]\mathit{ans} = [9, 8, 6]
  • a=[0,6,9]a = [0, 6, 9], ans=[9,9,12]\mathit{ans} = [9, 9, 12]
  • a=[0,6,9]a = [0, 6, 9], ans=[9,9,12]\mathit{ans} = [9, 9, 12]

In the second testcase, the only taster drinks min⁡(5,7)\min(5, 7) milliliters of tea of the only sort.

Here are the remaining amounts of each sort of tea after each step and the total amount of tea each taster has drunk for the third testcase:

  • a=[10,4,3,3]a = [10, 4, 3, 3], ans=[3,4,2,1]\mathit{ans} = [3, 4, 2, 1];
  • a=[6,2,2,3]a = [6, 2, 2, 3], ans=[3,8,4,2]\mathit{ans} = [3, 8, 4, 2];
  • a=[4,1,2,3]a = [4, 1, 2, 3], ans=[3,8,6,3]\mathit{ans} = [3, 8, 6, 3];
  • a=[3,1,2,3]a = [3, 1, 2, 3], ans=[3,8,6,4]\mathit{ans} = [3, 8, 6, 4].

Here are the remaining amounts of each sort of tea after each step and the total amount of tea each taster has drunk for the fourth testcase:

  • a=[999999999,999999999,0]a = [999999999, 999999999, 0], ans=[1,1,1000000000]\mathit{ans} = [1, 1, 1000000000];
  • a=[999999998,0,0]a = [999999998, 0, 0], ans=[1,2,1999999999]\mathit{ans} = [1, 2, 1999999999];
  • a=[0,0,0]a = [0, 0, 0], ans=[1,2,2999999997]\mathit{ans} = [1, 2, 2999999997].

第一个测试用例已在题目描述中给出。以下是每一步操作后各类茶的剩余量,以及每位品茶师已饮茶的总量:

  • a=[1,12,9]a = [1, 12, 9], ans=[9,8,6]\mathit{ans} = [9, 8, 6]
  • a=[0,6,9]a = [0, 6, 9], ans=[9,9,12]\mathit{ans} = [9, 9, 12]
  • a=[0,6,9]a = [0, 6, 9], ans=[9,9,12]\mathit{ans} = [9, 9, 12]

在第二个测试用例中,唯一的一位品茶师饮用了唯一一类茶中 min⁡(5,7)\min(5, 7) 毫升。

以下是第三个测试用例中,每一步操作后各类茶的剩余量,以及每位品茶师已饮茶的总量:

  • a=[10,4,3,3]a = [10, 4, 3, 3], ans=[3,4,2,1]\mathit{ans} = [3, 4, 2, 1];
  • a=[6,2,2,3]a = [6, 2, 2, 3], ans=[3,8,4,2]\mathit{ans} = [3, 8, 4, 2];
  • a=[4,1,2,3]a = [4, 1, 2, 3], ans=[3,8,6,3]\mathit{ans} = [3, 8, 6, 3];
  • a=[3,1,2,3]a = [3, 1, 2, 3], ans=[3,8,6,4]\mathit{ans} = [3, 8, 6, 4]。

以下是第四个测试用例中,每一步操作后各类茶的剩余量,以及每位品茶师已饮茶的总量:

  • a=[999999999,999999999,0]a = [999999999, 999999999, 0], ans=[1,1,1000000000]\mathit{ans} = [1, 1, 1000000000];
  • a=[999999998,0,0]a = [999999998, 0, 0], ans=[1,2,1999999999]\mathit{ans} = [1, 2, 1999999999];
  • a=[0,0,0]a = [0, 0, 0], ans=[1,2,2999999997]\mathit{ans} = [1, 2, 2999999997]。

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

首页