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. EVC入门之二: 在未被加载的DLL中设置断点 (虽然没有遇到这个问题,不过先摘抄下来)

    问题: 这个问题居然也郁闷了我一段时间. 我们假设在EVC里建立了一个project, 里面有SubProject_1(以下简称SB1,嘿嘿), 编译生成一个EXE; SubProject_2(以下简 ...

  2. 微信小程序module.exports 模块化

    //common.js var studentList = [     {         name: "xiaoming",         age: "22" ...

  3. PS 色调— —颜色梯度

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  4. laravel 5.4 运行 make:auth 报错

    Laravel 5.4 migrate时报错: Specified key was too long error 问题根源 MySQL支持的utf8编码最大字符长度为3字节,如果遇到4字节的宽字符就会 ...

  5. bzoj2309 CTSC2011 字符串重排

    题意: 给定n个字符串S1,S2,S3,...,Sn,把它们排序 设排序结果为Sp1,Sp2,Sp3,...,Spn 现在给定q个任务,每个任务的格式都是"要求在排序结果中Sa恰好在Sb前一 ...

  6. nginx中共享内存的使用

    在nginx的进程模型下,类似流量统计.流量控制.数据共享.等需要多个工作进程共同配合完成任务,共享内存是一个重要的进程通讯的方案.本文介绍在nginx的代码中与共享内存相关的功能,包括ngx_shm ...

  7. Java多线程运行机制的基本原理

    Java多线程运行机制的基本原理 进程和线程的区别 进程 进程是一个程序执行的实例,比如说我们打开10个IE浏览器窗口,那么就有10个进程开启.一个进程可以同时被运行若干次,进程是CPU进行资源分配和 ...

  8. openStack高可用性和灾备方案

    1. 基础知识 1.1 高可用 (High Availability,简称 HA) 高可用性是指提供在本地系统单个组件故障情况下,能继续访问应用的能力,无论这个故障是业务流程.物理设施.IT软/硬件的 ...

  9. 在多台手机上批量安装apk

    1.手机要打开adb调试 2.该程序可以实现台android手机的多个apk批量安装 1.getSeriaoNum.py模块,该模块获取已连接手机的序列号 import os import threa ...

  10. 使用VSTO写的一个工作证打印软件

    转行做HR近2年.最近公司要做工牌,工牌上要打印照片,姓名,工号和部门等信息.一共1000多人,如果手工排版手工打印的话,估计要死人. 于是coding的老毛病又犯了,想写个程序来打印工牌.还是拿最近 ...