CF1809F.Traveling in Berland

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn cities in Berland, arranged in a circle and numbered from 11 to nn 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 nn 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 ii to the city (i mod n)+1(i \bmod n) + 1 (i.e. from 11 to 22, from 22 in 33, ..., from nn to 11).

The fuel tank of your car holds up to kk liters of fuel. To drive from the ii-th city to the next one, aia_i liters of fuel are needed (and are consumed in the process).

Every city has a fuel station; a liter of fuel in the ii-th city costs bib_i 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.

伯兰德有 nn 座城市,它们呈环形排列,并按顺时针方向编号为 11 到 nn。

你想环游整个伯兰德:从某座城市出发,访问其余所有城市,最后返回出发城市。不幸的是,你只能沿伯兰德环形高速公路行驶,该公路连接全部 nn 座城市。这条公路由一位极富声望且备受尊敬的部长设计,因此是单向的——仅允许顺时针通行,即仅能从城市 ii 驾车前往城市 (i mod n)+1(i \bmod n) + 1(即从 11 到 22,从 22 到 33,……,从 nn 到 11)。

你的汽车油箱最多可容纳 kk 升燃油。从第 ii 座城市驶向下一座城市需消耗 aia_i 升燃油(并在行驶过程中被完全消耗)。

每座城市均设有加油站;在第 ii 座城市购买 1 升燃油的价格为 bib_i 伯尔(burles)。城市之间不允许加油;若在两城之间燃油耗尽,则视为旅程失败。

对每座城市,请计算以该城市为起点和终点完成整个旅程所需的最低花费。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn and kk (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5; 1≤k≤1091 \le k \le 10^9) — the number of cities and the volume of fuel tank, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤k1 \le a_i \le k).

The third line contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤bi≤21 \le b_i \le 2).

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

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

每个测试用例的第一行包含两个整数 nn 和 kk(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5;1≤k≤1091 \le k \le 10^9)—— 城市数量和油箱容量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤k1 \le a_i \le k)。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤21 \le b_i \le 2)。

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

输出格式

For each test case, print nn integers, where the ii-th of them is equal to the minimum cost of the journey if you start and finish in the ii-th city.

对于每个测试用例,输出 nn 个整数,其中第 ii 个整数表示从第 ii 个城市出发并最终回到第 ii 个城市的旅程的最小花费。

输入输出样例

  • 输入#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

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

首页