CF260C.Balls and Boxes

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.

Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting balls (one at a time) to the boxes with numbers i + 1, i + 2, i + 3 and so on. If Vasya puts a ball into the box number n, then the next ball goes to box 1, the next one goes to box 2 and so on. He did it until he had no balls left in his hands. It is possible that Vasya puts multiple balls to the same box, and it is also possible that one or more balls will go to the box number i. If i = n, Vasya puts the first ball into the box number 1, then the next ball goes to box 2 and so on.

For example, let's suppose that initially Vasya had four boxes, and the first box had 3 balls, the second one had 2, the third one had 5 and the fourth one had 4 balls. Then, if i = 3, then Vasya will take all five balls out of the third box and put them in the boxes with numbers: 4, 1, 2, 3, 4. After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 4 balls, 3 in the second one, 1 in the third one and 6 in the fourth one.

At this point Vasya has completely forgotten the original arrangement of the balls in the boxes, but he knows how they are arranged now, and the number x — the number of the box, where he put the last of the taken out balls.

He asks you to help to find the initial arrangement of the balls in the boxes.

小瓦西亚的房间里有 nn 个装着球的盒子。这些盒子排成一行,从左到右依次编号为 11 到 nn。

有一次,瓦西亚选择了一个盒子,假设其编号为 ii,并从中取出了所有球(题目保证该盒子最初至少有一个球),然后开始将这些球逐个放入编号为 i+1i+1、i+2i+2、i+3i+3、…… 的盒子中。如果瓦西亚要将一个球放入编号为 nn 的盒子,则下一个球将放入编号为 11 的盒子,再下一个放入编号为 22 的盒子,依此类推。他持续这一过程,直到手中没有剩余球为止。同一个盒子可能被放入多个球;也可能有一个或多个球被放入编号为 ii 的盒子中。特别地,若 i=ni = n,则瓦西亚首先将第一个球放入编号为 11 的盒子,第二个球放入编号为 22 的盒子,依此类推。

例如,假设最初瓦西亚有四个盒子,其中第一个盒子有 33 个球,第二个盒子有 22 个球,第三个盒子有 55 个球,第四个盒子有 44 个球。若 i=3i = 3,则瓦西亚将从第三个盒子中取出全部 55 个球,并依次放入编号为 4, 1, 2, 3, 44,\,1,\,2,\,3,\,4 的盒子中。经过上述操作后,各盒子中的球数变为:第一个盒子有 44 个球,第二个盒子有 33 个球,第三个盒子有 11 个球,第四个盒子有 66 个球。

此时,瓦西亚已完全忘记了盒子中球的初始分布情况,但他知道当前各盒子中的球数,以及数字 xx —— 即他所取出的球中最后一个球被放入的盒子编号。

他请你帮忙找出盒子中球的初始分布情况。

输入格式

The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers _a_1, _a_2, ..., a__n, where integer a__i (0 ≤ a__i ≤ 109, a__x ≠ 0) represents the number of balls in the box with index i after Vasya completes all the actions.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入的第一行包含两个整数 nn 和 xx(2≤n≤1052 \leq n \leq 10^5,1≤x≤n1 \leq x \leq n),分别表示盒子的总数以及瓦西亚投出最后一颗球所落入的盒子编号。
第二行包含 nn 个以空格分隔的整数 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n,其中整数 aia_i(0≤ai≤1090 \leq a_i \leq 10^9,且 ax≠0a_x \neq 0)表示瓦西亚完成所有操作后,编号为 ii 的盒子中所含球的数量。

请注意:在 C++ 中,请勿使用 %lld 说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.

输出 n 个整数,其中第 i 个整数表示 Vasya 开始操作前编号为 i 的盒子中的小球数量。输出的数字之间用空格分隔。如果存在多个正确解,输出任意一个即可。

输入输出样例

  • 输入#1

    4 4
    4 3 1 6

    输出#1

    3 2 5 4
  • 输入#2

    5 2
    3 2 0 2 7

    输出#2

    2 1 4 1 6
  • 输入#3

    3 3
    2 3 1

    输出#3

    1 2 3

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

首页