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 i from 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.

Sample test(s)
input
5
1 2 3 1 2
output
3 2 0 2 0 
input
4
3 2 1 4
output
2 3 4 0 

对于每个a[i]询问要加上多少值才能大于a[i]右边的最大的一个

这显然从后往前搜一遍完了

 #include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define inf 0x7fffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,a[],ans[];
int main()
{
n=read();
for(int i=;i<=n;i++)a[i]=read();
int mx=a[n]+;
for(int i=n-;i>=;i--)
{
ans[i]=max(,mx-a[i]);
mx=max(mx,a[i]+);
}
for(int i=;i<=n;i++)printf("%d ",ans[i]);
}

cf581B

cf581B Luxurious Houses的更多相关文章

  1. CF581B Luxurious Houses 模拟

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

  2. CF581B Luxurious Houses 题解

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

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

  4. 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. Codeforces Round #322 (Div. 2)

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

  7. CodeForces - 581B-Luxurious Houses

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

  8. UESTC 1817 Complete Building the Houses

    Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...

  9. cdoj 04 Complete Building the Houses 暴力

    Complete Building the Houses Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...

随机推荐

  1. Opencv学习笔记(六)SURF学习笔记

    原创文章,转载请注明出处:http://blog.csdn.net/crzy_sparrow/article/details/7392345 本人挺菜的,肯定有非常多错误纰漏之处 ,希望大家不吝指正. ...

  2. jquery实现图片切换和js实现图片切换

    jquery实现图片切换: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  3. 查看linux系统版本

    1.查看内核版本 #cat /proc/version Linux version 2.6.18-164.el5 (mockbuild@x86-003.build.bos.redhat.com) (g ...

  4. 富文本 SpannableString Span

    经典使用场景 SpannableStringBuilder needStartSSB = new SpannableStringBuilder("需要"); SpannableSt ...

  5. Linux命令之进程的管理

    1.进程介绍 进程的分类: 进程一般分为交互进程.批处理进程和守护进程三类. 守护进程总是活跃的,一般是后台运行,守护进程一般是由系统在开机时通过脚本自动激活启动或由超级管理用户root来启动.比如在 ...

  6. wxpython下的桥梁信息管理系统

    github地址:https://github.com/billiepander/BIMS 第一版: 现在实现了登陆,与部门级别用户录入桥梁检测信息后保存为excel(后期要用数据库存一些关键信息,为 ...

  7. CSS3 2D转换

    CSS3 转换 通过CSS3转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. 它如何工作? 转换是是元素改变形状.尺寸和位置的一种效果. 你可以使用2D或3D转换你的元素. 浏览器支持 属性 浏 ...

  8. android 检查网络是否可用,如果不可用弹出设置,让用户改变

    /** * 校验网络,如果没有网络,返回true * * @return boolean */ @Override public boolean hasInternetConnected() { Co ...

  9. Java sql helper[转]

    原文:http://www.cnblogs.com/beijiguangyong/archive/2011/12/10/2302737.html package sql; import java.sq ...

  10. DELL磁盘阵列控制卡(RAID卡)MegaCli常用管理命令汇总

    新版本的 MegaCli-1.01.24-0.i386.rpm (下载地址:http://www.lsi.com/downloads/Public/MegaRAID Common Files/8.02 ...