Luxurious Houses

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let‘s enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all ifrom 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1?≤?n?≤?105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers hi (1?≤?hi?≤?109), where hi equals the number of floors in the i-th house.

Output

Print n integers a1,?a2,?...,?an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero.

All houses are numbered from left to right, starting from one.

Example

Input

51 2 3 1 2

Output

3 2 0 2 0 

Input

43 2 1 4

Output

2 3 4 0 
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n;
 4 long long int num[100005],maxn;
 5 int main()
 6 {
 7     while(~scanf("%d",&n))
 8     {
 9         for(int i = 0; i < n; i++)
10             scanf("%lld",&num[i]);
11
12         maxn = num[n-1];
13         num[n-1] = 0;
14         for(int i = n-2; i >= 0; i--)
15         {
16             if(num[i] <= maxn)
17             {
18                 num[i] = maxn - num[i] + 1;
19             }
20             else
21             {
22                 maxn = num[i];
23                 num[i] = 0;
24             }
25         }
26         for(int i = 0; i < n; i++)
27         {
28             printf("%lld",num[i]);
29             if(i!=n-1) printf(" ");
30         }
31         printf("\n");
32     }
33     return 0;
34 }
时间: 2024-10-10 10:53:00

Luxurious Houses的相关文章

cf581B Luxurious Houses

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be lu

CF581B Luxurious Houses 模拟

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be lu

【Henu ACM Round#19 B】 Luxurious Houses

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从右往左维护最大值. 看到比最大值小(或等于)的话.就递增到比最大值大1就好. [代码] #include <bits/stdc++.h> using namespace std; const int N = 1e5; int a[N+10],n; int main() { cin >> n; for(int i = 1;i <= n;i++) cin >> a[i]; int now=0; fo

2017-5-7-Train: Codeforces Round #322 (Div. 2)

A. Vasya the Hipster(水题) One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the l

cf 581B-------Luxurious Houses

题目: The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to b

UESTC 4 Complete Building the Houses 树状数组

题目来源: http://acm.uestc.edu.cn/#/problem/show/4 分析:就是一个很普通的区间修改,单点查询的树状数组,但是今天忘记吃药了,一直写不对,中午迷迷糊糊地,直接把数据读入到数组里而不是update,然后又总是考虑后面的数被减到0以下要怎么处理,其实根本不用考虑,直接判断大于0就行了,要是修改那些值,就无法满足数组a[]的性质了(a[]是原式的做差,a[i] = x[i] - x[i-1], a[1] = x[1]).想想还是贴出来纪念一下(这有什么好纪念的?

cdoj 04 Complete Building the Houses 暴力

Complete Building the Houses Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/3 Description Bear has a large, empty ground for him to build a home. He decides to build a row of houses, one after another, say n in t

hlg1392Leyni, LOLI and Houses【网络流+二分+floyed】

今天过了几道网络流的题, 下面下一下解题报告, 题目难易不是梯度的 ,还有一些题目的代码在 voj上 等有空会补上的 Leyni, LOLI and Houses Time Limit: 2000 MS Memory Limit: 65536 K Total Submit: 43(12 users) Total Accepted: 19(11 users) Rating:  Special Judge: No Description Leyni likes to play with LOLIs.

Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1?≤?pi?≤?n). Little penguin Polo loves walking ar