CF1809F.Traveling in Berland
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities in Berland, arranged in a circle and numbered from 1 to n in clockwise order.
You want to travel all over Berland, starting in some city, visiting all the other cities and returning to the starting city. Unfortunately, you can only drive along the Berland Ring Highway, which connects all n cities. The road was designed by a very titled and respectable minister, so it is one-directional — it can only be traversed clockwise, only from the city i to the city (imodn)+1 (i.e. from 1 to 2 , from 2 in 3 , ..., from n to 1 ).
The fuel tank of your car holds up to k liters of fuel. To drive from the i -th city to the next one, ai liters of fuel are needed (and are consumed in the process).
Every city has a fuel station; a liter of fuel in the i -th city costs bi burles. Refueling between cities is not allowed; if fuel has run out between cities, then your journey is considered incomplete.
For each city, calculate the minimum cost of the journey if you start and finish it in that city.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains two integers n and k ( 3≤n≤2⋅105 ; 1≤k≤109 ) — the number of cities and the volume of fuel tank, respectively.
The second line contains n integers a1,a2,…,an ( 1≤ai≤k ).
The third line contains n integers b1,b2,…,bn ( 1≤bi≤2 ).
The sum of n over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case, print n integers, where the i -th of them is equal to the minimum cost of the journey if you start and finish in the i -th city.
输入输出样例
输入#1
4 3 5 3 4 4 1 2 2 5 7 1 3 2 5 1 2 1 1 1 2 4 3 1 2 1 3 2 2 2 2 3 2 2 2 2 1 2 1
输出#1
17 19 17 13 12 12 12 14 14 14 14 14 8 8 8