首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >CodeForces - 260C

CodeForces - 260C

作者头像
风骨散人Chiam
发布于 2020-10-28 02:04:15
发布于 2020-10-28 02:04:15
36300
代码可运行
举报
文章被收录于专栏:CSDN旧文CSDN旧文
运行总次数:0
代码可运行

CodeForces - 260C

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 4balls. 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.

Input

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 a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 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.

Output

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.

Examples

Input

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
4 4
4 3 1 6

Output

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3 2 5 4 

Input

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
5 2
3 2 0 2 7

Output

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
2 1 4 1 6 

Input

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3 3
2 3 1

Output

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1 2 3 

思维题,逆推,讨论最小值,与结束点的位置关系,逆推回去即可。
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
#define LL long long
#define M 1000000007
LL a[maxn];
int main()
{
    LL n,i,x,minn=0x7f7f7f7f,j,y;
    cin>>n>>x;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]<=minn)
        {
            if(a[i]==minn&&j<=x&&i>x)
            continue;
            else
                minn=a[i],j=i;
        }
    }
    if(x<j)
    {
        y=x+(n-j)+a[j]*n;
        for(i=1; i<=n; i++)
        {
            if(i!=j)
                a[i]=a[i]-a[j];
            if(i<=x||i>j)
                a[i]--;
            if(i==j)
                cout<<y<<' ';
            else
                cout<<a[i]<<' ';
        }
    }
    else if(x==j)
    {
        y=a[j]*n;
        for(i=1; i<=n; i++)
        {
            if(i!=j)
                a[i]=a[i]-a[j];
            if(i!=j)
                cout<<a[i]<<' ';
            else
                cout<<y<<' ';
        }
    }
    else
    {
        y=x-j+a[j]*n;
        for(i=1; i<=n; i++)
        {
            if(i!=j)
                a[i]=a[i]-a[j];
            if(i>j&&i<=x)
                a[i]--;
            if(i==j)
                cout<<y<<' ';
            else
                cout<<a[i]<<' ';
        }
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
【CodeForces】554C - CodeForces 554C(组合数学)
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color ibefore drawing the last ball of color i + 1 for all i from 1 to k - 1. Now he wonders how many different ways this can happen.
FishWang
2025/08/26
870
【CodeForces】233B - Non-square Equation(思维)
where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.
FishWang
2025/08/26
720
Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) B. Cards Sorting 树状数组+技巧
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
glm233
2020/09/28
4520
CF思维联系– Codeforces-988C Equal Sums (哈希)
这个题,无论怎么循环都是超时的,所以必须想到一种不需要循环的方法,这里我用的是hash,因为是每个序列删掉一个之后相等,那我们就保存删掉一个数之后的值,用hash存起来,如果再遇到而且不是同一个序列的话,那就是可以构造出提要求的两个序列。
风骨散人Chiam
2020/11/03
6250
CF思维联系– CodeForces - 991C Candies(二分)
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
风骨散人Chiam
2020/10/28
5350
Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive par
Angel_Kitty
2018/04/09
9900
【Codeforces】1216B - Shooting
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
喜欢ctrl的cxk
2019/11/08
6960
codeforce 270C Magical Boxes
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
风骨散人Chiam
2020/10/28
4190
Codeforces Round #483 (Div. 2) D. XOR-pyramid
For an array bb of length mm we define the function ff as
用户2965768
2018/08/30
5640
CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)
如果把a1,a2,a3....an的系数取出,会有如下规律1,11,111,1111C00​C10​C20​C30​
风骨散人Chiam
2020/11/06
3630
Codeforces Round #395 (Div. 2)(A.思维,B,水)
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ili
Angel_Kitty
2018/04/08
7800
CF--思维练习-- CodeForces - 215C - Crosses(思维题)
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).
风骨散人Chiam
2020/10/29
5050
codeforce 227D Naughty Stone Piles (贪心+递归+递推)
Description There are n piles of stones of sizes a1, a2, …, an lying on the table in front of you.
风骨散人Chiam
2020/10/28
4440
Codeforces Round #559 (Div. 2)B. Expansion coefficient of the array
Let's call an array of non-negative integers a1,a2,…,ana1,a2,…,an a kk-extension for some non-negative integer kk if for all possible pairs of indices 1≤i,j≤n1≤i,j≤n the inequality k⋅|i−j|≤min(ai,aj)k⋅|i−j|≤min(ai,aj) is satisfied. The expansion coefficient of the array aa is the maximal integer kk such that the array aa is a kk-extension. Any array is a 0-expansion, so the expansion coefficient always exists.
glm233
2020/09/28
6230
Codeforces Round #547 (Div. 3)C. Polycarp Restores Permutation
An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2], [1][1], [1,2,3,4,5][1,2,3,4,5] and [4,3,1,2][4,3,1,2]. The following arrays are not permutations: [2][2], [1,1][1,1], [2,3,4][2,3,4].
glm233
2020/09/28
5060
Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and
Angel_Kitty
2018/04/09
6880
Codeforces 626D Jerry's Protest(暴力枚举+概率)
2018-2019 ICPC, NEERC, Southern Subregional Contest D. Garbage Disposal
Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.
glm233
2020/09/28
3760
Codeforces Round #624 (Div. 3) B - WeirdSort
You are also given a set of distinct positions p1,p2,…,pmp1,p2,…,pm, where 1≤pi<n1≤pi<n. The position pipi means that you can swap elements a[pi]a[pi] and a[pi+1]a[pi+1]. You can apply this operation any number of times for each of the given positions.
glm233
2020/09/28
5430
CodeForces - 260B
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
风骨散人Chiam
2020/10/28
3400
Codeforces Round #629 (Div. 3) F. Make k Equal (技巧暴力,类前缀和,思维,数学)
You are given the array aa consisting of nn elements and the integer k≤nk≤n.
glm233
2020/09/28
4840
相关推荐
【CodeForces】554C - CodeForces 554C(组合数学)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验