Very interesting greed:
Let's reformulate the condition in terms of a certain height the towers, which'll be is on the stairs. Then an appropriate amount of money of a person in the queue are equal to the height of the tower with the height of the St EP at which the tower stands. And the process of moving in the queue would be equivalent to raising a tower on the top step, and the one in whose place I T came Up-down. As shown in the illustrations. Then, it becomes apparent, and that's the tower on the steps to be sorted, it's enough to sort the tower without The height of step it stays. Total complexity of sorting is O (Nlog (n)).
G. Happy linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
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 ofNBerland 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 personaStands just behind personb, then personaCan pay personb1 dollar, thenaandbGet swapped. Of course, if personaHave zero dollars, he can not swap places with personb.
Res Idents 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, the line or the the one in front of who another resident stands with not less than 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?000)-the number of residents who stand in the line.
The second line containsNspace-separated integers ai (0?≤? a i? ≤?109 ), where ai is the number of berland dollars of a man standing on theI-th position in the line. The positions is numbered starting from theEndof 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 is equal to the Nu Mber of Money's on position I in the new line. If There is multiple answers, print any of them.
Sample Test (s) input
211 8
Output
Input
510 9 7) 10 6
Output
:(
Input
312 3 3
Output
Note
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 dollars WI ll equal to: 4 4. In this line everybody would be happy.
/* ***********************************************author:ckbosscreated time:2015 June 09 Tuesday 00:24 13 seconds file Name : cf549.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;const int Maxn=200200;int N,a[maxn],base[maxn],b[maxn];int Main () {//freopen ("In.txt", "R", stdin);//freopen ("OUT.txt", "W" , stdout); scanf ("%d", &n), for (int i=0;i<n;i++) {scanf ("%d", a+i); base[i]=n-1-i;b[i]=a[i]-base[i];} Sort (b,b+n); bool Flag=true;for (int i=0;i<n;i++) {a[i]=base[i]+b[i];if (i&&a[i]<a[i-1]) {flag=false; Break;}} if (Flag==false) {puts (":(");} else{for (int i=0;i<n;i++) printf ("%d%c", A[i], (i==n-1)? 10:32);} return 0;}
Codeforces 549G. Happy Line Greedy