#Lutece1863. 除草

除草

Migrated from Lutece 1863 除草

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

nn 棵草,起始高度均为 0,每棵草每天长高 viv_i。有 mm 个除草计划 (did_i, hih_i):在第 did_i 天结束后,将所有草超过 hih_i 的部分除掉,输出除掉部分的总高度和。n,m5105n,m \leq 5\cdot 10^5, vi106v_i \leq 10^6, di,hi1012d_i, h_i \leq 10^{12},保证 did_i 递增。

Input

第一行两个数 n, m。第二行 n 个数表示每棵草的生长速度。接下来 m 行,每行两个数,表示计划日和计划高度。

Output

输出 m 行,每行一个数,每个计划的除草量。

Samples

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

Note

Day 除草前 除草后 除草量
1 [1, 2, 4, 3] [1, 1, 1, 1] 6
2 [2, 3, 5, 4] [2, 2, 2, 2]
3 [3, 4, 6, 5] [0, 0, 0, 0] 18
4 [1, 2, 4, 3] [1, 2, 3, 3] 1

Resources

每周一题 Div. 1