Evacuation

아직 제출이 없습니다시간 제한6초메모리 제한1024 MB

문제

There are N+2N+2 towns in a straight line. The towns are numbered from 00 through N+1N+1 from left to right. Each town ii (1iN1 \leq i \leq N) has a shelter which can contain up to A_iA\_i people.

Currently, SS people are traveling together and visiting one of the towns. However, you don't know which town they are visiting.

You just got to know that there are QQ meteorites that can hit the towns. The ii-th meteorite may strike towns L_i,L_i+1,,R_iL\_i,L\_i+1,\cdots,R\_i. To ensure the safety of the travelers, for each meteorite, you want to calculate the evacuation cost.

The evacuation cost for a meteorite is calculated as follows:

  • The evacuation cost is the minimum total cost needed to make all travelers safe no matter which town they are visiting.
  • A person is safe if he/she is in a shelter or a town outside the effect of the meteorite.
  • It takes 11 unit cost to move one person to an adjacent town (two towns are adjacent iff their numbers differ by exactly 11).

Note that only moving people costs money, and other actions (like accommodating people in a shelter) don't. It is guaranteed that towns 00 and N+1N+1 will never be affected by meteorites, so it is always possible to make all travelers safe.

Write a program that, for each meteorite, calculates the evacuation cost for that meteorite.

입력

Input is given from Standard Input in the following format:

NN SS

A_1A\_1 A_2A\_2 \cdots A_NA\_N

QQ

L_1L\_1 R_1R\_1

L_2L\_2 R_2R\_2

\vdots

L_QL\_Q R_QR\_Q

출력

Print QQ lines. The ii-th line should contain the evacuation cost for the meteorite ii.

제한

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1S10121 \leq S \leq 10^{12}
  • 0A_iS0 \leq A\_i \leq S
  • A_1+A_2++A_N1012A\_1+A\_2+\cdots+A\_N \leq 10^{12}
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1L_iR_iN1 \leq L\_i \leq R\_i \leq N
  • All values in input are integers.

힌트

  • For the first meteorite, it takes 1414 unit costs when the travelers are visiting the town 22.
  • For the second meteorite, it takes 1010 unit costs when the travelers are visiting the town 44.
  • For the third meteorite, it takes 1313 unit costs when the travelers are visiting the town 33.