G. Happy Line
time limit per test
memory limit per test
input
output
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.
strictly smaller
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
Input
n (1 ≤ n ≤ 200 000) — the number of residents who stand in the line.
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
Output
":(" 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
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
经过观察会发现,一个人无论走到哪个位置,他的钱数加上位置标号的总值是不变的
所以把每个人的金额加上位置标号,从小到大排序,再减去位置标号,此时判断队列中的金额数是否呈非递减
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
typedef long long ll;
using namespace std;
ll num[maxn];
int main(){
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%I64d", num+i);
num[i] += i;
}
sort(num+1, num+1+n);
for(int i = 1; i <= n; i++)
num[i] -= i;
for(int i = 2; i <= n; i++){
if(num[i] < num[i-1]){
puts(":(");
return 0;
}
}
printf("%I64d", num[1]);
for(int i = 2; i <= n; i++)
printf(" %I64d", num[i]);
puts("");
return 0;
}