传送门:http://codeforces.com/problemset/problem/272/C

C. Dima and Staircase
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an(1 ≤ a1 ≤ a2 ≤ ... ≤ an).

Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws each box vertically down on the first wi stairs of the staircase, that is, the box covers stairs with numbers1, 2, ..., wi. Each thrown box flies vertically down until at least one of the two following events happen:

  • the bottom of the box touches the top of a stair;
  • the bottom of the box touches the top of a box, thrown earlier.

We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn't taken into consideration. Specifically, that implies that a box with width wi cannot touch the stair number wi + 1.

You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of n integers, a1, a2, ..., an (1 ≤ ai ≤ 109; ai ≤ ai + 1).

The next line contains integer m (1 ≤ m ≤ 105) — the number of boxes. Each of the following m lines contains a pair of integers wi, hi(1 ≤ wi ≤ n; 1 ≤ hi ≤ 109) — the size of the i-th thrown box.

The numbers in the lines are separated by spaces.

Output

Print m integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64dspecifier.

Examples
input
5
1 2 3 6 6
4
1 1
3 1
1 1
4 3

output
1
3
4
6

input
3
1 2 3
2
1 1
3 1

output
1
3

input
1
1
5
1 2
1 10
1 10
1 10
1 10

output
1
3
13
23
33

Note

The first sample are shown on the picture.

#include<iostream>using namespace std;long long a[1000000],i,j,n,m,h1,L,h,w;
int main()
{cin>>n;for (i=1; i<=n; i++)cin>>a[i];cin>>m;for (i=0; i<m; i++){cin>>w>>h;L=max(L+h1,a[w]);cout<<L<<endl;h1=h;}return 0;
}

CODEFORCES 272C Dima and Staircase 细节理解题+简单技巧相关推荐

  1. Codeforces - 272C Dima and Staircase(思维)

    题目链接---- Dima's got a staircase that consists of n stairs. The first stair is at height a1, the seco ...

  2. CodeForces - 272C Dima and Staircase (线段树区间更新)

    题意: 见以下样例,给出 5 个区间,每个区间的高度已知.一共 4 次操作.每次操作都是从最左边开始向下垒一个宽为 w 高为h 的木块,过程见下图. 问每次垒木块的高度是多少? Input 5 1 2 ...

  3. Codeforces 272C Dima and Staircase 思维 or 线段树

    点击打开链接 题意:给出n个物品高度ai,ai<=1e9,ai非递减,n,m<=1e5,m个方块的宽度和高度,问m个方块依次落下时达到的高度 每次都从左端点1开始叠放,第i个方块肯定落在第 ...

  4. Codeforces Round #700 (Div. 2)A~D2解题报告

    Codeforces Round #700 (Div. 2)A~D2解题报告 A Yet Another String Game 原题链接 http://codeforces.com/contest/ ...

  5. Codeforces Round #693 (Div. 3)A~G解题报告

    Codeforces Round #693 (Div. 3)A~G解题报告 A Cards for Friends 原题信息 http://codeforces.com/contest/1472/pr ...

  6. Codeforces Round #697 (Div. 3)A~G解题报告

    Codeforces Round #697 (Div. 3)A~G解题报告 题 A Odd Divisor 题目介绍 解题思路 乍一想本题,感觉有点迷迷糊糊,但是证难则反,直接考虑没有奇数因子的情况, ...

  7. codeforces 400D Dima and Bacteria 并查集+floyd

    题目链接:http://codeforces.com/problemset/problem/400/D 题目大意: 给定n个集合,m步操作,k个种类的细菌, 第二行给出k个数表示连续的xi个数属于i集 ...

  8. Codeforces Round #827 (Div. 4) G. Orray 解题报告

    原题链接: Problem - G - Codeforces 题目描述: You are given an array aa consisting of nn nonnegative integers ...

  9. codeforces 814B.An express train to reveries 解题报告

    题目链接:http://codeforces.com/problemset/problem/814/B 题目意思:分别给定一个长度为 n 的不相同序列 a 和 b.这两个序列至少有 i 个位置(1 ≤ ...

最新文章

  1. github自己的仓库给别人上传代码的操作
  2. ​“好师父”如何破解大学生就业难题
  3. 平均股价的时间序列图形_美股技术分析 神奇的九转序列
  4. 谈谈java面向对象思想_对于Java面向对象思想的理解
  5. w8计算机配置要求,win8系统最低配置要求有哪些|win8系统是否有最低配置要求-系统城...
  6. 大数据学习笔记59:初探Kafka消息系统
  7. maya mel uf8_如何在maya中创建uv 的mel语言
  8. opengl光线追踪的程序_【PathTracing】实时光线追踪和BSSRDF的那些事
  9. c3p0使用 与批量生成
  10. 没有人能拒绝这个网站,没有人!
  11. 仿微信在线聊天源码 DuckChat聊天系统PHP采用 PHP 编写的聊天软件,简直就是一个完整的迷你版微信
  12. Gifxing在线图片无损压缩,gif压缩
  13. UTF-8、BOM、feff的问题
  14. 这一刻我學會了堅強、給我一雙翅膀,我会向天空去翱翔。
  15. 手机上如何学会使用计算机,手机如何投屏到win7电脑上_手机投屏到win7电脑的详细方法...
  16. 特殊符号♪♫♩♬♭♪♫♩♬♭
  17. iOS打开沙盒html,ios 开发中,沙盒目录解释
  18. 一文了解蛋白功能结构域预测与分析
  19. 2021最新 wordpress+xampp+阿里云建站过程(超级详细)
  20. 使用erlang ranch tcp开发服务端

热门文章

  1. React 调和(Reconciler)原理理解
  2. 结构与算法 7-32 哥尼斯堡的“七桥问题” (25 分)
  3. vue开发公众号-关闭浏览器返回主公众号
  4. Centos7 安装RTL8723BE无线网卡驱动
  5. Leetcode575:分糖果
  6. 新研究起底人类和机器注意力机制的区别|一周AI最火论文
  7. 企业信息安全保护模式
  8. 并发编程的三大特性——原子性,可见性,有序性
  9. 小米商城app端项目
  10. iOS11界面交互设计规范(iOS 11 Human Interface Guidelines)