Hot Water Pipe
题号:NC237336
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述


There is a long hot water pipe consisting of  sections, each with a capacity of  unit volume. The  sections are numbered  to  from the left to the right to match the direction of water flow in the pipe.

The initial temperature of the water in section  is  and it will drop by  unit every minute. To keep the water warm enough, once the temperature of the water in a section is lower than , it will be heated to  immediately (the heating time can be ignored). When the water in the -th section is used, the water in the -th section will move to the -th section for all  (note that the movements will be completed immediately which means the temperature of the water will not change), and the hot water of temperature  will be added to section  at the same time. Please note that heat transfer effects are not considered in this problem.

Now, there are  operations using hot water. Each operation can be described as two integers , denoting using  units volume of water after  minutes since the last operation (or since the initial time if it is the first operation). Note that the operation is completed immediately. Please output  for every operation, where  stands for the average temperature of the water used. It can be shown that  must be an integer.

输入描述:

The first line of the input contains four integers  .

The second line contains  intergers, indicating   respectively.

Each of the next  lines contains two integers  , indicating an operation using  units volume of water after  minutes since the last operation.

输出描述:

For each operation, output a line containing an integer representing your answer.
示例1

输入

复制
8 4 18 26
19 20 21 22 23 24 25 26
2 2
10 5
4 10
2 3

输出

复制
47
104
225
72

说明

Explanation of example:

When the first operation was performed, the temperature of water in section  is  respectively, therefore the answer is .

When the second operation was performed, the temperature of water in section  is  respectively, therefore the answer is .

When the third operation was performed, the temperature of water in section  is  respectively, therefore the answer is .

When the fourth operation was performed, the temperature of water in section  is  respectively, therefore the answer is .