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 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.

Examples
input
2
11 8
output
9 10 
input
5
10 9 7 10 6
output
:(
input
3
12 3 3
output
4 4 10 
Note

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.


官方题解:

G. Happy Line

Authors: 2222MrDindows

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 illustrations. 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)).

 


很类似于371E中让严格递减变为不严格的做法

考虑位于i位置上的元素,要想让他和最后一个元素在同一地位上比较,只需要-(n-i),然后排序

排序后每个位置元素的实际值是+n-i

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+,INF=1e9+;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,a[N];
int main(){
n=read();
for(int i=;i<=n;i++) a[i]=read()-(n-i);
sort(a+,a++n);
for(int i=;i<n;i++) if(a[i]+n-i>a[i+]+n-i-){printf(":(");return ;}
for(int i=;i<=n;i++) printf("%d ",a[i]+n-i);
}

Codeforces 549G Happy Line[问题转换 sort]的更多相关文章

  1. CodeForces 549G Happy Line

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

  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 Round #258 (Div. 2) B. Sort the Array(简单题)

    题目链接:http://codeforces.com/contest/451/problem/B --------------------------------------------------- ...

  4. 【CF 549G Happy Line】排序

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

  5. codeforces 652D D. Nested Segments(离散化+sort+树状数组)

    题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. Codeforces Round #258 (Div. 2)——B. Sort the Array

    B. Sort the Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces 259 B - Little Pony and Sort by Shift

    题目链接:http://codeforces.com/contest/454/problem/B 解题报告:太渣了,这个模拟题最后跑大数据的时候挂了,最后还花了很久才过,用的最笨的方法,直接模拟,代码 ...

  8. codeforces A. Cinema Line 解题报告

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

  9. Codeforces Round #258 (Div. 2) B. Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...

随机推荐

  1. 从0开始学angularjs-笔记02

    上一节课主要跟大家讲解了angularjs的几种特性和看了一个简单的双向绑定的例子.最近都没有时间写博客了....忙成狗呀...今天周末,在写一篇吧~~ 今天主要跟大家详细讲解一下angularjs的 ...

  2. SubSonic2.2框架的使用方法和配置说明

    网上.net ORM框架也不少,但是我感觉这个框架配置很简单的,前几年貌似用的人很多,现在好像用得比较少了,随着它官方的升级现在已经到3.0了, 并且采用T4 模板生成的方式,代码量好像减少了.不过我 ...

  3. ABAP--在查询条件只包含部分索引字段时,如何使用索引

    One of the most important considerations when writing a select statement against a large table is th ...

  4. PHP代码审计中你不知道的牛叉技术点

    一.前言 php代码审计如字面意思,对php源代码进行审查,理解代码的逻辑,发现其中的安全漏洞.如审计代码中是否存在sql注入,则检查代码中sql语句到数据库的传输 和调用过程. 入门php代码审计实 ...

  5. SharePoint 2013 中如何使用Silverlight

    1.打开VS,创建一个Silverlight程序,如下图: 2.配置选择默认的,当然也可以不勾选Host Application,如下图: 3.添加Silverlight控件,2个label和1个bu ...

  6. [javascript svg fill stroke stroke-width rx ry ellipse 属性讲解] svg fill stroke stroke-width ellipse 绘制椭圆属性讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  7. Revit如何模型导入到InfraWorks中

    Infraworks也就是以前的Autodesk Infrastructure Modeler(AIM)作为一款优秀的概念设计软件,能接收来自各种来源的数据,这篇介绍如何把revit中的建筑模型导入到 ...

  8. Android 项目框架

  9. Android项目实战(二十):浅谈ListView悬浮头部展现效果

    先看下效果:需求是 滑动列表 ,其中一部分视图(粉丝数,关注数这一部分)在滑动到顶端的时候不消失,而是停留在整个界面头部. 我们先分析要解决的问题: 1.如何实现列表ListView顶部视图跟随Lis ...

  10. iOS拨打电话的三种方式

    iOS拨打电话的三种方式 1,这种方法,拨打完电话回不到原来的应用,会停留在通讯录里,而且是直接拨打,不弹出提示 1 2 var string = "tel:" + "1 ...