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 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).
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.
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.
5
1 2 3 1 2
3 2 0 2 0
4
3 2 1 4
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的更多相关文章
- CF581B Luxurious Houses 模拟
The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...
- CF581B Luxurious Houses 题解
Content 一条大街上有 \(n\) 个房子,第 \(i\) 个房子的楼层数量是 \(h_i\).如果一个房子的楼层数量大于位于其右侧的所有房屋,则房屋是豪华的.对于第 \(i\) 个房子,请求出 ...
- 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 ...
- Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...
- 【Henu ACM Round#19 B】 Luxurious Houses
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从右往左维护最大值. 看到比最大值小(或等于)的话.就递增到比最大值大1就好. [代码] #include <bits/std ...
- Codeforces Round #322 (Div. 2)
水 A - Vasya the Hipster /************************************************ * Author :Running_Time * C ...
- CodeForces - 581B-Luxurious Houses
The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...
- UESTC 1817 Complete Building the Houses
Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...
- cdoj 04 Complete Building the Houses 暴力
Complete Building the Houses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...
随机推荐
- SKCropNode类
继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode) NSCopying(SKNode) NSObject(NSObject) 框架 /System/ ...
- Android-Uiautomator:[5]停止monkey测试
方法/步骤 1 其实停止很简单,无非就是结束掉monkey的进程即可 如何停止呢 2 ps命令 查找uiautomator的进程 打开cmd命令行窗口 输入: adb shell ps | grep ...
- c++对象模型之Data布局
Data语意学 class X{}; class Y : publicvirtual X {}; class Z : publicvirtual X {}; class A : publicY, pu ...
- 枚举的基本使用方法 Enumerations
枚举的基本使用方法 Enumerations Enumeration enum SomeEnumeration{ case enumeration1 case enumeration2 case ...
- JDKSDK配置
变量名:ANDROID_HOME 变量值: E:\android-sdk_r11-windows\android-sdk_r11-windowsclsspath .;%JAVA_HOME%\l ...
- JAVA try-catch-finally-return
正常执行流程: try执行,遇到异常就跳到catch执行(以使得程序不会崩溃): 不管有没有异常catch,最后都执行finally 含return语句执行流程分析: 若try块中return ...
- C:应用于字符串处理函数
出于对C的不够熟悉,在读代码的过程中,平凡出现的字符串处理函数,成为了一个理解代码的大问题. 为了更方便的读取和理解代码,特意将接触到的字符串处理函数列出,方便查询: 1.strstr(str1,st ...
- Dev GridControl 按条件合并相同单元格
Dev 默认的合并方式,只要(垂直方向)相邻两个单元格的值相同都会进行合并,这种方式并不是最优的,所以需要在进行合并的过程中进行判断. 方式如下: 1:先设置需要合并的列为允许合并 OptionsVi ...
- TreeView控件之,后台构建TreeView(WinForm小程序)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX0AAAIdCAIAAABeBzrBAAAgAElEQVR4nOzdd5Qc130n+tl/nr3e5+
- Linq使用GroupBy筛选数据
StringBuilder sb = new StringBuilder(); List<IGrouping<string, modle>> listRepeat = mode ...