301388: CF260C. Balls and Boxes
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Balls and Boxes
题意翻译
有$N$个盒子,每个盒子中有若干个球(也可能为空),从某个盒子$i$中取出所有球,依次放到$i+1,i+2...N-1,N,1,2...$中,(每次放一个),直至球放完。注意:盒子中可能会放多次球,$i$号盒子中也有可能放球。现在已知盒子的个数、最后一个放球的位置,求出最开始每个盒子中放的球的个数。(输出任意一组即可)题目描述
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.输入输出格式
输入格式
The first line of the input contains two integers $ n $ and $ x $ ( $ 2<=n<=10^{5} $ , $ 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}<=10^{9} $ , $ 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.
输出格式
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.
输入输出样例
输入样例 #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