【Codeforces 549G】【贪心】Happy Line

Happy Line

Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Description

Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people, so each person agrees to swap places with the person right behind him for just 1 dollar. More formally, if person a stands just behind person b, then person a can pay person b 1 dollar, then a and b get swapped. Of course, if person a has zero dollars, he can not swap places with person b.
Residents of Berland are strange people. In particular, they get upset when there is someone with a strictly smaller sum of money in the line in front of them.
Can you help the residents of Berland form such order in the line so that they were all happy? A happy resident is the one who stands first in the line or the one in front of who another resident stands with not less number of dollars. Note that the people of Berland are people of honor and they agree to swap places only in the manner described above.

Input

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of residents who stand in the line.
The second line contains n space-separated integers ai (0 ≤ ai ≤ 109), where ai is the number of Berland dollars of a man standing on the i-th position in the line. The positions are numbered starting from the end of the line.

Output

If it is impossible to make all the residents happy, print “:(” without the quotes. Otherwise, print in the single line n space-separated integers, the i-th of them must be equal to the number of money of the person on position i in the new line. If there are multiple answers, print any of them.

Samples

Input1

2
11 8

Output1

9 10

Input2

5
10 9 7 10 6

Output2

:(

Input3

3
12 3 3

Output3

4 4 10

Hint

In the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line.
In the second sample it is impossible to achieve the desired result.
In the third sample the first person can swap with the second one, then they will have the following numbers of dollars: 4 11 3, then the second person (in the new line) swaps with the third one, and the resulting numbers of dollars will equal to: 4 4 10. In this line everybody will be happy.

Source

Looksery Cup 2015

题目大意:给定一个长为n 的序列 ai ,你可以执行任意次操作,每次操作可以交换两个相邻位置(i,i + 1) 上的数,且交换后位置上的数变为( ai+1,ai1 ),问是否能通过任意次操作使得ai 不降,若有解则给出最终的 ai

大概就是这样,然后我们可以把公式推出来
先假设有两个点x,y,移动后的位置是u和v(设u< v),然后我们根据题意可以写出来a[x]-(x-u)<=a[y]-(y-v)
然后可以化简得a[x]+x<=a[y]+y+(u-v)
u-v<0
∴初始的时候a[x]+x< a[y]+y
然后我们就可以按照a[i]+i排序,得到最后的顺序,然后再模拟检验是不是符合不下降就可以了

程序如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<stack>
#define INF 2100000000
#define ll long long
#define clr(x)  memset(x,0,sizeof(x))
#define clrmax(x)  memset(x,127,sizeof(x))

using namespace std;

inline int read()
{
    char c;
    int ret=0;
    while(!(c>='0'&&c<='9'))
        c=getchar();
    while(c>='0'&&c<='9')
    {
        ret=(c-'0')+(ret<<1)+(ret<<3);
        c=getchar();
    }
    return ret;
}

#define M 200005

struct node 
{
    int no,num;
}a[M];

int n,y[M];

bool com(node a,node b)
{
    return a.no+a.num<b.no+b.num;
}

int main()
{
    n=read();
    for(int i=1;i<=n;i++)
    {
        a[i].num=read();
        a[i].no=i;
    }
    sort(a+1,a+n+1,com);
    a[1].num-=1-a[1].no;
    int last=a[1].num;
    for(int i=2;i<=n;i++)
    {
        a[i].num-=i-a[i].no;
        if(a[i].num<last)
        {
            printf(":(");
            return 0;
        }
        last=a[i].num;
    }
    for(int i=1;i<=n;i++)
        printf("%d ",a[i].num);
    return 0;
}

大概就是这个样子,如果有什么问题,或错误,请在评论区提出,谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值