B. Luxurious Houses

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/581/problem/B

Description

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 Input

5
1 2 3 1 2

Sample Output

3 2 0 2 0

HINT

题意

在一个一维坐标系上有n个house

每个house显得厉害,就是他的楼层要比比他编号大的楼层都要高

然后问你每栋楼至少得加高多少

题解:

扫一遍就好了,其实就是一个查询最大值的过程

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1205000
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
#define lowbit(x) (x)&(-x)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
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 Max[maxn];
int a[maxn];
int main()
{
int n=read();
for(int i=;i<=n;i++)
a[i]=read();
int tmp = ;
for(int i=n;i>=;i--)
{
Max[i]=tmp+;
tmp = max(tmp,a[i]);
}
for(int i=;i<=n;i++)
printf("%d ",Max[i]>a[i]?Max[i]-a[i]:); }

Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题的更多相关文章

  1. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  2. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  3. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  4. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  5. Codeforces Round #357 (Div. 2) B. Economy Game 水题

    B. Economy Game 题目连接: http://www.codeforces.com/contest/681/problem/B Description Kolya is developin ...

  6. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  7. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  8. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  9. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

随机推荐

  1. C语言中的位拷贝与值拷贝浅谈(转载)

    注:C语言实现的PHP变量的赋值过程中,就涉及到了 深拷贝和浅拷贝 位拷贝拷贝的是地址(也叫浅拷贝),而值拷贝则拷贝的是内容(深拷贝).深拷贝和浅拷贝可以简单理解为:如果一个类拥有资源,当这个类的对象 ...

  2. BZOJ_1027_[JSOI2007]_合金_(计算几何+Floyd求最小环)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1027 共三种金属,\(m\)种材料,给出每种材料中三种金属的占比. 给出\(n\)种合金的三种 ...

  3. BZOJ3792: 跑步

    题解: 感觉被坑出翔... 显然我们把矩阵乘法中的点当成原图中的边就可以了. 先写opertor 在struct里面居然只能带一个变量?... 放到外面,然后还得加引用? 然后题目描述不清,重边怎么算 ...

  4. TCP编程(七)

    此为网络编程的一个系列,后续会把内容补上...

  5. ZOJ 2283 Challenge of Wisdom

    题意:在一个n * m的地图里,有p个宝藏,每次只能向横纵坐标增加的方向走,问最少走几次能把宝藏都拿走. 解法:按横坐标排序,纵坐标的一个不下降子序列就是一条合法路径,要求多少条不下降子序列可以覆盖所 ...

  6. 并发编程之--ConcurrentSkipListMap

    概要 本章对Java.util.concurrent包中的ConcurrentSkipListMap类进行详细的介绍.内容包括:ConcurrentSkipListMap介绍ConcurrentSki ...

  7. Tomcat 7 Connector 精读(2) 协议处理器 Http11Protocol(待续)

    . Http11Protocol是阻塞式IO的实现,上图的几个方法是它的生命周期相关的方法.

  8. 【转】C数据存储(包括const存储在哪,C++不同部分我在文中用红字已指出)

    非原创(文中红字为自己见解,如有不对,请大神指点) 程序由指令和数据组成,C语言程序亦是如此.开发者在编写程序的时候往往需要根据不同数据的特点以及程序需求来选择不同的数据存储方式,那么在C语言中数据的 ...

  9. sys.stdout 重定向

    通俗的来说,sys.stdout的功能类似与C++里面的文件输出功能fprintf. 接下来直接入正题,让我们来看代码: >>> import sys >>> te ...

  10. 关于ANSI 和 Unicode

    关于ANSI和Unicode 1.ANSI American National Standards Institute(美国国家标准学会),ANSI编码不是一种具体的编码方式,而是一种指定在某些环境下 ...