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/# ...
随机推荐
- ICMP报文分析
一.概述: 1. ICMP同意主机或路由报告差错情况和提供有关异常情况.ICMP是因特网的标准协议,但ICMP不是高层协议,而是IP层的协议.通常ICMP报文被IP层或更高层协议(TCP或UDP) ...
- [Angular 2] Handling Click Events with Subjects
While Angular 2 usually uses event handlers to manage events and RxJS typically uses Observable.from ...
- 开发中可能会用到的几个 jQuery 小提示和技巧 (转)
转自:http://www.cnblogs.com/lhb25/p/useful-jquery-tips-and-tricks.html 今天,我们将分享一些很有用的技巧和窍门给 jQuery 开发人 ...
- java相关的路径获取 (转载 http://tomfish88.iteye.com/blog/971255)
在jsp和class文件中调用的相对路径不同.在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getProp ...
- location.href的用法
*.location.href 用法: top.location.href=”url” 在顶层页面打开url(跳出框架) self.location.href=”url” ...
- WEB文件上传下载功能
WEB文件上传下载在日常工作中经常用到的功能 这里用到JS库 http://files.cnblogs.com/meilibao/ajaxupload.3.5.js 上传代码段(HTML) <% ...
- UGUI之UI的深度问题
学过NGUI的都知道,NGUI的深度是通过值来控制的.Panel也是UI也是,如果空间太多,布局复杂UI深度的值会变得很混乱.所以在NGUI中设置UI深度时一定要多加思考.然而在UGUI控制显示顺序的 ...
- C# - 使用 OLEDB读取 excel(不用Excel对象).
参考: How to read from an Excel file using OLEDB 为了使用方便,我做成了工具类(OledbCommon.cs),好以后使用. 注:连接字符串中,Provid ...
- 安全管理:IE6安全隐患重重 为何不离不弃
安全服务商Zscaler的报告称,尽管微软IE6曾遭受一系列强势攻击并且新出的IE版本有更强的安全性能,但IE6依然受到各企业的热捧. 尽管微软一直敦促用户部署浏览器更新(截止2010年八月就将满九年 ...
- 在浏览器中打不开Oracle 11gR2的企业管理器页面
最简单的办法,重建EM 四个步骤: emca -repos drop emca -repos create emca -config dbcontrol db emctl start dbconsol ...