CF260C.Balls and Boxes

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

Once Vasya chose one of the boxes, let's assume that its number is ii , 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+1i+1 , i+2i+2 , i+3i+3 and so on. If Vasya puts a ball into the box number nn , then the next ball goes to box 11 , the next one goes to box 22 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 ii . If i=ni=n , Vasya puts the first ball into the box number 11 , then the next ball goes to box 22 and so on.

For example, let's suppose that initially Vasya had four boxes, and the first box had 33 balls, the second one had 22 , the third one had 55 and the fourth one had 44 balls. Then, if i=3i=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,44,1,2,3,4 . After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 44 balls, 33 in the second one, 11 in the third one and 66 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 xx — 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.

输入格式

The first line of the input contains two integers nn and xx ( 2<=n<=1052<=n<=10^{5} , 1<=x<=n1<=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 nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} , where integer aia_{i} ( 0<=ai<=1090<=a_{i}<=10^{9} , ax0a_{x}≠0 ) represents the number of balls in the box with index ii 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.

输出格式

Print nn integers, where the ii -th one represents the number of balls in the box number ii 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.

输入输出样例

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