Happy Line

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

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
2
11 8
Output
9 10 
Input
5
10 9 7 10 6
Output
:(
Input
3
12 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.

 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; struct Node
{
int v;
int id;
}a[]; bool cmp(Node x,Node y)
{
return (x.v+x.id)<(y.v+y.id);
} int main()
{
int n;
int i,j;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&a[i].v);
a[i].id=i;
}
sort(a+,a+n+,cmp);
int flg=;
for(i=;i<=n;i++)
{
a[i].v=a[i].v-(i-a[i].id);
if(a[i].v< || (i>= && a[i].v<a[i-].v))
flg=;
}
if(flg==)
{
printf("%d",a[].v);
for(i=;i<=n;i++)
printf(" %d",a[i].v);
printf("\n");
}
else
{
printf(":(\n");
}
return ;
}

CodeForces 549G Happy Line的更多相关文章

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

    G. Happy Line time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces 549G. Happy Line 馋

    非常有趣的贪婪: Let's reformulate the condition in terms of a certain height the towers, which will be on t ...

  3. codeforces A. Cinema Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...

  4. 【CF 549G Happy Line】排序

    题目链接:http://codeforces.com/problemset/problem/549/G 题意:给定一个n个元素的整数序列a[], 任意时刻对于任一对相邻元素a[i-1]. a[i],若 ...

  5. codeforces B. Shower Line 解题报告

    题目链接:http://codeforces.com/contest/431/problem/B 题目意思:给出5 * 5 的矩阵.从这个矩阵中选出合理的安排次序,使得happiness之和最大.当第 ...

  6. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  7. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  8. 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/p ...

  9. Codeforces Round #466 (Div. 2) -A. Points on the line

    2018-02-25 http://codeforces.com/contest/940/problem/A A. Points on the line time limit per test 1 s ...

随机推荐

  1. 夺命雷公狗---node.js---21之项目的构建在node+express+mongo的博客项目6之数据的遍历

    首先还是来链接数据库,然后就查找,如下所示: /** * Created by leigood on 2016/8/31. */ var express = require('express'); v ...

  2. switch结构2016/03/08

    Switch  03/08 一.结构 switch(){  case *: ;break;……default: ;brek;} 练习:输入一个日期,判断这一年第几天? Console.Write(&q ...

  3. php文件上传参数设置

    php默认的 上传文件大小是2M,要上传超过此大小的文件,需要设置php和apache的一些参数,具体参考如下: 1.file_uploads:是否允许通过HTTP上传文件的开关,默认为ON就是开 2 ...

  4. js表单提交一种方式

    在一个html和php混编的文件中,用到js提交表单的方法: 定义表单id为form1,提交按钮type为submit, var data_info = document.getElementById ...

  5. (function($){...})(jQuery) 函数详解

    function(arg){...} 这是一个匿名函数,参数是arg. 而调用匿名函数时,是在函数后面写上括号和实参的,由于操作符的优先级,函数本身也需要用括号,即: function(arg){.. ...

  6. less文件的样式无法生效的一个原因,通过WEB浏览器访问服务器less文件地址返回404错误

    有一种情况容易导致less文件的样式无法生效,就是部分服务器(以IIS居多)会对未知后缀的文件返回404,导致无法正常读取.less文件.解决方案是在服务器中为.less文件配置MIME值为text/ ...

  7. Reporting Service报表项默认可见+号和-号的显示问题

    在Reporting Service里面可以设置报表项(组.tablix行.tablix列.文本框等所有SSRS报表项)的可见性,并且可以设置某个报表项的可见性由点击另外一个报表项来控制,比如报表项A ...

  8. 单例模式在Java和C#中的实现

    单例模式算是最常见和最容易理解一种设计模式了.通常是指某一个类只有一实例存在,存在的空间我认为可以理解为该类所在的应用系统内,还有一种是在某一个容器内单一存在,比如像spring的IOC容器(作用域为 ...

  9. 161125、Java网络编程之统一资源定位符URL

    统一资源定位符URL(Uniform Resource Locator)是www客户机访问Internet时用来标识资源的名字和地址.超文本链路由统一资源定位符URL维持.URL的格式是: <M ...

  10. top.location.href和localtion.href有什么不同

    top.location.href=”url”          在顶层页面打开url(跳出框架) self.location.href=”url”         仅在本页面打开url地址 pare ...