非常有趣的贪婪:

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

 

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 persona 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 thei-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 test(s)
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.

/* ***********************************************
Author :CKboss
Created Time :2015年06月09日 星期二 00时24分13秒
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;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

Codeforces 549G. Happy Line 馋的更多相关文章

  1. CodeForces 549G Happy Line

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

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

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

  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. POJ3617 Best Cow Line 馋

    虽然这个问题很简单,但非常好,由于过程是很不错的.发展思路的比较 并鼓励人们,不像有些贪心太偏,推动穷人,但恼人 鉴于长N弦S,然后又空字符串STR.每当有两个选择 1:删S增加虚假的第一要素STR于 ...

  7. [codeforces 549]G. Happy Line

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

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

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

随机推荐

  1. excel使用cube

  2. The Dole Queue

    The Dole Queue Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit cid ...

  3. JSTL解析——001

    JSTL 全称jsp standard tag library ,即jsp标准标签库. 是不是想问标签是什么东西? 标签就是jsp专门用于显示数据的,可重复利用的类库: 是不是想问标签由那些部分组成的 ...

  4. WITH+HInt MATERIALIZE 不见得有效

    那个要多次调用才需要物化的. 只调用一次,物化没用 MATERIALIZE  语法:MATERIALIZE  描述:指示优化器将内联视图实体化————执行过程中会创建基于视图的临时表. with dd ...

  5. TPL异步并行编程之任务超时

    此处参考自阿涛的博文:http://www.cnblogs.com/HelloMyWorld/p/5526914.html 一 自己定义 基本的思路: net中异步操作由于是交给线程来实现,因此不可能 ...

  6. Qt之生成Window资源文件(.rc 文件)

    简述 qmake 可以随意地自动生成一个适当填充的 Windows 资源文件.本节主要讲解如何用 qmake 处理一个 Windows 资源文件,并将其链接到一个可执行应用程序(EXE)或动态链接库( ...

  7. Lucene.Net 2.3.1开发介绍 —— 一、接触Lucene.Net

    原文:Lucene.Net 2.3.1开发介绍 -- 一.接触Lucene.Net 1.引用Lucene.Net类库找到Lucene.Net的源代码,在“C#\src\Lucene.Net”目录.打开 ...

  8. 修改Hosts文件

    Hosts文件是一个用于存储计算机网络中节点信息的文件,它可以将主机名映射到相应的IP地址,实现DNS的功能,它可以由计算机的用户进行控制. Hosts文件的存储位置在不同的操作系统中并不相同,甚至不 ...

  9. 9月mob(ShareSDK)活动预告,这个秋天非常热

    9月秋天来临,广州的天气依旧非常热,广州的活动氛围更热~ 先有GMGC B2B对接会在广州创新谷,再有上方网TFC全球移动游戏开发人员大会来袭,游戏圈的火越烧越旺,成都GMGDC全球移动游戏开发人员大 ...

  10. ThinkPhp学习07

    原文:ThinkPhp学习07 简单CRUD操作 public function show() { $m=M('User'); // $arr=$m->find(2); //查找id=2的数据, ...