CodeForces 549G 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
2
11 8
9 10
5
10 9 7 10 6
:(
3
12 3 3
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的更多相关文章
- Codeforces 549G Happy Line[问题转换 sort]
G. Happy Line time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 549G. Happy Line 馋
非常有趣的贪婪: Let's reformulate the condition in terms of a certain height the towers, which will be on t ...
- codeforces A. Cinema Line 解题报告
题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...
- 【CF 549G Happy Line】排序
题目链接:http://codeforces.com/problemset/problem/549/G 题意:给定一个n个元素的整数序列a[], 任意时刻对于任一对相邻元素a[i-1]. a[i],若 ...
- codeforces B. Shower Line 解题报告
题目链接:http://codeforces.com/contest/431/problem/B 题目意思:给出5 * 5 的矩阵.从这个矩阵中选出合理的安排次序,使得happiness之和最大.当第 ...
- [codeforces 549]G. Happy Line
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...
- [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 ...
- 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 ...
- 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 ...
随机推荐
- linux中启动与终止lnmp的脚本
说是lnmp, 其实暂时只是 lnp, 因为还没有安装 mysql 这是脚本: #!/bin/bash function lnmpstart() { nginx /usr/local/php/bin/ ...
- 【py网页】urllib.urlretrieve远程下载
下面我们再来看看 urllib 模块提供的 urlretrieve() 函数.urlretrieve() 方法直接将远程数据下载到本地. 1 >>> help(urllib.urlr ...
- ASP.NET MVC API 路由生成规则
我们都知道调用ASP.NET MVC的某些API函数(诸如:Url.Action.RedirectToAction等)可以生成URL,ASP.NET MVC会根据调用API函数时传入的参数去匹配系统定 ...
- Robotium Recorder的初试
一.安装 资料来自官方 Prerequisites: Install the Java JDK. Install the Android SDK. The ADT bundle with Eclips ...
- python爬虫框架scrapy实例详解
生成项目scrapy提供一个工具来生成项目,生成的项目中预置了一些文件,用户需要在这些文件中添加自己的代码.打开命令行,执行:scrapy st... 生成项目 scrapy提供一个工具来生成项目,生 ...
- Index Condition Pushdown Optimization
Index Condition Pushdown (ICP) is an optimization for the case where MySQL retrieves rows from a tab ...
- zabbix监控mysql主从
最近在公司搭建了zabbix监控系统,现在需要用zabbix来监控mysql的主从同步情况 现在说一下配置的详细步骤: 1.首先给mysql分配一个监控的账号: mysql> grant rep ...
- 5.1JavaScript精华
9.使用Promises Promises,是Javascript表现item的一种方式.它执行异步工作,在未来的某个时间点完成.遇到最多的promises,是使用Ajax请求.浏览器在后台发起HTT ...
- textarea 在浏览器中禁用拖动和固定大小
HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...
- javascript——web前端编程
一.弹出提示框: 连接 function disp_prompt() { var name=prompt("请输入您的名字","Bill Gates") ...