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.

Examples

Input

5
1 2 3 1 2

Output

3 2 0 2 0 

Input

4
3 2 1 4

Output

2 3 4 0 

思路:从后边扫,去看是否大于当前的最大值,然后就更新

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std; const int maxn=100005; int a[maxn],b[maxn];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int Max=0;
for(int i=n-1;i>=0;i--)
{
if(a[i]>Max) b[i]=a[i];
else if(a[i]==Max) b[i]=0;
else
b[i]=Max;
Max=max(Max,a[i]);
}
for(int i=0;i<n-1;i++)
{
if(b[i]==a[i]) printf("0 ");
else if(b[i]==0) printf("1 ");
else
printf("%d ",b[i]-a[i]+1);
}
printf("0\n");
return 0;
}

CodeForces - 581B-Luxurious Houses的更多相关文章

  1. Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题

    B. Luxurious Houses Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/pr ...

  2. cf581B Luxurious Houses

    The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...

  3. Luxurious Houses

    The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...

  4. CF581B Luxurious Houses 模拟

    The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...

  5. 【Henu ACM Round#19 B】 Luxurious Houses

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从右往左维护最大值. 看到比最大值小(或等于)的话.就递增到比最大值大1就好. [代码] #include <bits/std ...

  6. CF581B Luxurious Houses 题解

    Content 一条大街上有 \(n\) 个房子,第 \(i\) 个房子的楼层数量是 \(h_i\).如果一个房子的楼层数量大于位于其右侧的所有房屋,则房屋是豪华的.对于第 \(i\) 个房子,请求出 ...

  7. Codeforces Round #322 (Div. 2)

    水 A - Vasya the Hipster /************************************************ * Author :Running_Time * C ...

  8. Codeforces Round #501 (Div. 3) 1015D Walking Between Houses

    D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces Round #501 (Div. 3) D. Walking Between Houses

    题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n ...

随机推荐

  1. 一小时搞明白自定义注解(Annotation)

    原文链接:http://blog.csdn.net/u013045971/article/details/53433874 什么是注解 Annotation(注解)就是Java提供了一种元程序中的元素 ...

  2. javascript(8)

      给对象添加方法还有两种方式: 第一种: function 类名(){ this.属性; } var 对象名=new 类名(); function 函数名(){ //执行 } 对象名.属性名=函数名 ...

  3. Win7、Win8、Win10始终以管理员身份运行程序。

    在Win7.Win8.Win10系统中,以管理员身份运行程序很麻烦,一般有以下几种方式: 1.在可执行程序或快捷方式上右键,以管理员身份运行: 2.在可执行程序或快捷方式上右键->属性-> ...

  4. nodejs && apidoc

    1. 安装nodejs      http://www.nodejs.org      源码编译      configure —prefix=/usr/local/nodejs      make ...

  5. VC6.0实用小技巧

    VC6.0的若干实用小技巧 .检测程序中的括号是否匹配 把光标移动到需要检测的括号(如大括号{}.方括号[].圆括号()和尖括号<>)前面,键入快捷键 “Ctrl+]”.如果括号匹配正确, ...

  6. javacv实现实时视频截图和录像服务easyCV

    本项目维护于github:https://github.com/eguid/easyCV 1.介绍 本项目基于javaCV1.4.x. 其中实现了 (1)实时视频截图服务(支持rtsp/rtmp/ht ...

  7. Linux中vsftpd安装和配置

    目录 Redhat/CentOS安装vsftp软件 Ubuntu/Debian安装vsftp软件 Redhat/CentOS安装vsftp软件 1. 安装vsftp $ yum install vsf ...

  8. Linux的学习思路

    自学嵌入式确实不大现实(当然也不是说没有这个可能),毕竟嵌入式难度也是比较大的. 嵌入式的应用主要是几个方向, 一是系统开发:侧重开发环境搭建.内核原理.交叉编译等: 二是嵌入式Linux应用开发:侧 ...

  9. Windows窗体间的数据交互

    轻松掌握Windows窗体间的数据交互                                     作者:郑佐 2004-04-05 Windows 窗体是用于 Microsoft Win ...

  10. mysql create table