#P5579. [PA 2015] Siano

[PA 2015] Siano

Description

Farmer Byteasar bought a piece of land with area nn mu, and he wants to grow grass on it.

On each mu of land, he plants a unique type of grass. The grass on the ii-th mu grows by aia_i centimeters every day.

Byteasar will harvest mm times. The ii-th harvest happens on day did_i, and he cuts off all parts whose height is greater than or equal to bib_i.

Byteasar wants to know, for each harvest, what the total height of grass obtained is. Can you help him?

Input Format

The first line contains two positive integers n,mn, m, representing the number of mu and the number of harvests.

The second line contains nn positive integers. The ii-th number is aia_i, describing the growth rate of the grass on each mu.

In the next mm lines, each line contains two integers di,bid_i, b_i, describing each harvest in order.

Output Format

Output mm lines. Each line contains one integer, answering in order the total height of grass obtained in each harvest.

4 4
1 2 4 3
1 1
2 2
3 0
4 4
6
6
18
0

Hint

For 100%100\% of the testdata, 1n,m5×1051 \le n, m \le 5 \times 10^5, 1ai1061 \le a_i \le 10^6, 1di10121 \le d_i \le 10^{12}, 0bi10120 \le b_i \le 10^{12}.

The testdata guarantees that d1<d2<<dmd_1 < d_2 < \dots < d_m, and at any time, the height of the grass on any mu never exceeds 101210^{12}.

Translated by ChatGPT 5