Happy LineTime limit:1000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 549G
Description
Do you like summer? Residents of Berland do. They especially love eating ice cream on the hot summer. So the summer day a large queue of n berland residents lined up in front of the ice cream stall. We know that each of the them have a certain amount of berland dollars with them. The residents of Berland is nice people, so all 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 is strange people. In particular, they get upset when there are 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, they were all happy? A Happy resident is the one who stands first and the line or the one in front of who another resident stands with n OT less number of dollars. Note that the people of Berland is 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)-the number of residents who stand in the L ine.
The second line contains n space-separated integers ai (0≤ a I ≤109), where a I was the number of berland dollars of a man standing on the i-th position in the line. The positions is 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 "line" n space-separated integers, the i-th of them must be equal T o The number of money of the WHO on position I in the new line. If There is multiple answers, print any of them.
Sample Input
Input
2
11 8
Output
Input
5
10 9 7) 10 6
Output
:(
Input
3
12 3 3
Output
Hint
In the first sample of residents should swap places, after the first resident have dollars and he is at the head O f The line and the second resident would have 9 coins and he'll be in the end of the line.
In the second sample it was impossible to achieve the desired result.
In the third sample the first person can swap with the second one and then they would have the following numbers of dollars: C0>4 3, then the second person (on the new line) swaps with the third one, and the resulting numbers of the dollars would EQ UAL to: 4 4 10. In this line everybody would be happy.
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 structNode7 {8 intv;9 intID;Ten}a[200005]; One A BOOLcmp (Node x,node y) - { - return(X.v+x.id) < (y.v+y.id); the } - - intMain () - { + intN; - inti,j; +scanf"%d",&n); A for(i=1; i<=n;i++) at { -scanf"%d",&a[i].v); -A[i].id=i; - } -Sort (A +1, a+n+1, CMP); - intflg=1; in for(i=1; i<=n;i++) - { toa[i].v=a[i].v-(I-a[i].id); + if(a[i].v<0|| (i>=2&& a[i].v<a[i-1].v)) -flg=0; the } * if(flg==1) $ {Panax Notoginsengprintf"%d", a[1].v); - for(i=2; i<=n;i++) theprintf"%d", A[I].V); +printf"\ n"); A } the Else + { -printf":(\ n"); $ } $ return 0; -}View Code
Codeforces 549G Happy Line