#P5579. [PA 2015] Siano
[PA 2015] Siano
Description
Farmer Byteasar bought a piece of land with area 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 -th mu grows by centimeters every day.
Byteasar will harvest times. The -th harvest happens on day , and he cuts off all parts whose height is greater than or equal to .
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 , representing the number of mu and the number of harvests.
The second line contains positive integers. The -th number is , describing the growth rate of the grass on each mu.
In the next lines, each line contains two integers , describing each harvest in order.
Output Format
Output 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 of the testdata, , , , .
The testdata guarantees that , and at any time, the height of the grass on any mu never exceeds .
Translated by ChatGPT 5
京公网安备 11011102002149号