您的位置:首页 > 其它

Looksery Cup 2015

2016-03-12 13:19 260 查看
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.

Examples

Input
2
11 8


Output
9 10


Input
5
10 9 7 10 6


Output
:(


Input
3
12 3 3


Output
4 4 10


Note
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.

【题意】给了n个数,只能进行一种操作,即当满足当前这个数比上一个小时,上一个数可以以减掉1的代价和当前这个数交换位置,问能否通过一些操作,让n个数的序列按照从大到小的顺序进行排列。如果不能,输出一个特殊符号,如果能输出变化后的这个序列。

【解题思路】贪心加排序,变换后的某个数的值和没变化之前的值有关系,这是我看样例猜的,按照yy思路敲一发,发现wr在test6,想了好久,感觉没什么问题,改不过来,看了题解,发现题解和我只是排序方式不一样而已(-><-)。

【AC代码】

#include <bits/stdc++.h>
using namespace std;

const int nn = 200010;
struct node{
int val,id;
friend bool operator<(const node &aa,const node &bb)
{
return aa.val+aa.id<bb.val+bb.id;
}
}a[nn];
int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i].val);
a[i].id = i;
}
sort(a+1,a+n+1);
bool ok = true;
a[0].val = 0,a[0].id = 0;
for(int i=1; i<=n; i++)
{
a[i].val = a[i].val-(i-a[i].id);
if(a[i].val<0||a[i].val<a[i-1].val)
{
ok=false;
break;
}
}
if(ok==false)
puts(":(");
else
{
for(int i=1; i<=n; i++)
{
printf("%d ",a[i].val);
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: