Codeforces 549G. Happy Line greedy, codeforces549g

Source: Internet
Author: User

Codeforces 549G. Happy Line greedy, codeforces549g


Interesting greedy:


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 tower stands. and the process of moving in the queue will be equivalent to raising a tower on the top step, and the one in whose place it came up-down. as shown in the specified strations. then, it becomes apparent that to make all of the tower on the steps to be sorted, it is 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 in the hot summer. So this summer day a large queueNBerland 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 personAStands just behind personB, Then personACan pay personB1 dollar, thenAAndBGet swapped. Of course, if personAHas zero dollars, he can not swap places with personB.

Residents of Berland are strange people. In particle, 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 integerN(1 digit ≤ DigitNLimit ≤ limit 200 0000000)-the number of residents who stand in the line.

The second line containsNSpace-separated integersAI(0 bytes ≤ bytesAILimit ≤ limit 109), whereAIIs the number of Berland dollars of a man standing onI-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 lineNSpace-separated integers,I-Th of them must be equal to the number of money of the person on positionIIn the new line. If there are multiple answers, print any of them.

Sample test (s) input
211 8
Output
9 10 
Input
510 9 7 10 6
Output
:(
Input
312 3 3
Output
4 4 10 
Note

In the first sample two residents shoshould 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.



/*************************************** * ******** Author: CKbossCreated Time: Tuesday, January 1, June 09, 2015 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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.