CF1795C.Tea Tasting
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A tea manufacturer decided to conduct a massive tea tasting. n sorts of tea will be tasted by n tasters. Both the sorts of tea and the tasters are numbered from 1 to n . The manufacturer prepared ai milliliters of the i -th sort of tea. The j -th taster can drink bj milliliters of tea at once.
The tasting will be conducted in steps. During the first step, the i -th taster tastes the i -th sort of tea. The i -th taster drinks min(ai,bi) tea (how much is available of the i -th sort and how much the i -th taster can drink). ai also decreases by this amount.
Then all tasters move to the previous sort of tea. Thus, during the second step, the i -th taster tastes the (i−1) -st sort of tea. The i -th taster drinks min(ai−1,bi) tea. The 1 -st person ends the tasting.
During the third step, the i -th taster tastes the (i−2) -nd sort of tea. The 2 -nd taster ends the tasting. This goes on until everyone ends the tasting.
Take a look at the tasting process for n=3 , a=[10,20,15] , 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.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of testcases.
The first line of each testcase contains a single integer n ( 1≤n≤2⋅105 ) — the number of sorts of tea and the number of tasters.
The second line contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the amount of each sort of tea.
The third line contains n integers b1,b2,…,bn ( 1≤bi≤109 ) — the amount of tea each taster can drink at once.
The sum of n over all testcases doesn't exceed 2⋅105 .
输出格式
For each testcase, print n integers — the i -th value should be equal to the total amount of tea the i -th taster will drink.
输入输出样例
输入#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] , ans=[9,8,6]
- a=[0,6,9] , ans=[9,9,12]
- a=[0,6,9] , ans=[9,9,12]
In the second testcase, the only taster drinks 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] , ans=[3,4,2,1] ;
- a=[6,2,2,3] , ans=[3,8,4,2] ;
- a=[4,1,2,3] , ans=[3,8,6,3] ;
- a=[3,1,2,3] , 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] , ans=[1,1,1000000000] ;
- a=[999999998,0,0] , ans=[1,2,1999999999] ;
- a=[0,0,0] , ans=[1,2,2999999997] .