#abc270e. E - Apple Baskets on Circle

E - Apple Baskets on Circle

Score : 500500 points

问题描述

NN 个篮子按照编号 1,2,,N1, 2, \ldots, N 排成一个圆圈。
对于每个 1iN11\leq i \leq N-1,篮子 i+1i+1 紧邻在篮子 ii 的右侧,而篮子 11 则紧邻在篮子 NN 的右侧。

当前篮子 ii 中包含 AiA_i 个苹果。

高桥站在篮子 11 前面,并重复执行以下动作。

  • 如果他面对的篮子里有苹果,就拿一个吃掉。然后,无论他现在是否已经吃了一个苹果,都继续走向下一个紧邻在右侧的篮子。

当高桥总共吃掉了 KK 个苹果时,求每个篮子里剩余的苹果数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN baskets numbered 1,2,,N1, 2, \ldots, N arranged in a circle.
For each 1iN11\leq i \leq N-1, basket i+1i+1 is to the immediate right of basket ii, and basket 11 is to the immediate right of basket NN.

Basket ii now contains AiA_i apples.

Takahashi starts in front of basket 11 and repeats the following action.

  • If the basket he is facing contains an apple, take one and eat it. Then, regardless of whether he has eaten an apple now, go on to the next basket to the immediate right.

Find the number of apples remaining in each basket when Takahashi has eaten exactly KK apples in total.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 0Ai10120 \leq A_i \leq 10^{12}
  • 1K10121 \leq K \leq 10^{12}
  • There are at least KK apples in total. That is, i=1NAiK\sum_{i=1}^{N}A_i\geq K.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \ldots ANA_N

Output

Print NN integers, with spaces in between.
The ii-th integer should be the number of apples remaining in basket ii when Takahashi has eaten exactly KK apples in total.

Sample Input 1

3 3
1 3 0

Sample Output 1

0 1 0 

Takahashi will do the following.

  • Basket 11, which he is facing, contains an apple, so he takes one and eats it. Then, he goes on to basket 22. Now, the baskets have 0,3,00,3,0 apples.
  • Basket 22, which he is facing, contains an apple, so he takes one and eats it. Then, he goes on to basket 33. Now, the baskets have 0,2,00,2,0 apples.
  • Basket 33, which he is facing, contains no apple. Then, he goes on to basket 11. Now, the baskets have 0,2,00,2,0 apples.
  • Basket 11, which he is facing, contains no apple. Then, he goes on to basket 22. Now, the baskets have 0,2,00,2,0 apples.
  • Basket 22, which he is facing, contains an apple, so he takes one and eats it. Then, he goes on to basket 33. Now, the baskets have 0,1,00,1,0 apple(s).

Sample Input 2

2 1000000000000
1000000000000 1000000000000

Sample Output 2

500000000000 500000000000 

update @ 2024/3/10 11:23:40

}