CodeForces 549G Happy Line

Happy Line

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

Submit Status Practice CodeForces 549G

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.

Sample Input

Input

211 8

Output

9 10 

Input

510 9 7 10 6

Output

:(

Input

312 3 3

Output

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.

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 struct Node
 7 {
 8     int v;
 9     int id;
10 }a[200005];
11
12 bool cmp(Node x,Node y)
13 {
14     return (x.v+x.id)<(y.v+y.id);
15 }
16
17 int main()
18 {
19     int n;
20     int i,j;
21     scanf("%d",&n);
22     for(i=1;i<=n;i++)
23     {
24         scanf("%d",&a[i].v);
25         a[i].id=i;
26     }
27     sort(a+1,a+n+1,cmp);
28     int flg=1;
29     for(i=1;i<=n;i++)
30     {
31         a[i].v=a[i].v-(i-a[i].id);
32         if(a[i].v<0 || (i>=2 && a[i].v<a[i-1].v))
33             flg=0;
34     }
35     if(flg==1)
36     {
37         printf("%d",a[1].v);
38         for(i=2;i<=n;i++)
39             printf(" %d",a[i].v);
40         printf("\n");
41     }
42     else
43     {
44         printf(":(\n");
45     }
46     return 0;
47 }

时间: 2024-11-08 16:25:16

CodeForces 549G Happy Line的相关文章

Codeforces 549G. Happy Line 贪心

很有意思的贪心: Let's reformulate the condition in terms of a certain height the towers, which will be on the stairs. Then an appropriate amount of money of a person in the queue is equal to the height of the tower with the height of the step at which the t

Codeforces 549G Happy Line[问题转换 sort]

G. Happy Line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a larg

【CF 549G Happy Line】排序

题目链接:http://codeforces.com/problemset/problem/549/G 题意:给定一个n个元素的整数序列a[], 任意时刻对于任一对相邻元素a[i-1]. a[i],若a[i-1] < a[i] 则要依次执行如下两个操作: 1. a[i-1]--, a[i]++: 2. 交换a[i-1]和a[i]的位置. 经过若干次1.2操作后,若能使整个序列变成非降的,则输出最终的序列:否则输出":(". 数据范围:n 属于 [1, 2*10^5], a[i]

CodeForces 251A. Points on Line(数学 lower_bound )

题目链接:http://codeforces.com/problemset/problem/251/A Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance be

Codeforces Round #247 (Div. 2) B - Shower Line

模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ vector<int> a(5); for(int i = 0; i < 5; ++ i) a[i] = i; int g[5][5]; for(int i = 0 ; i < 5; ++ i){ for(int j = 0 ; j < 5; ++

Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列

B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/319/B Description There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who h

Codeforces 319B. Psychos in a Line【单调栈】

题目链接: http://codeforces.com/problemset/problem/319/B 题意: 一串数列,每一个值如果大于相邻右一位的值的话,那么就可以把右边这个值"吃掉"(右一位消失,原来的值不变),问需要吃多少次才能到达无法再吃的状态. 思路: 利用栈.遍历一遍数组,处理每个值的时候,如果栈顶的元素小于该值,那么将其弹出,知道栈顶元素大于该值或者栈为空,栈内的每个元素记录下一个属性:他是在第几次被"吃掉",进栈的新元素的被吃次数就是它弹出去的元

codeforces 710B B. Optimal Point on a Line(数学)

题目链接: B. Optimal Point on a Line 题意: 给出n个点,问找出一个点使得这个点到所有的点的距离和最小; 思路: 所有点排序后的中位数;这是一个结论; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #in

Codeforces Beta Round #7 C. Line (扩展欧几里德)

题目链接:http://codeforces.com/problemset/problem/7/C 给你一个直线方程,有整数解输出答案,否则输出-1. 扩欧模版题.这里有讲解:http://www.cnblogs.com/Recoder/p/5459812.html (很久没写exgcd,都不会写了) 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 5 LL exgcd(LL a , LL