ICPC PACNW 2016 J - Shopping

View as PDF

Submit solution


Points: 15
Time limit: 2.5s
Memory limit: 256M

Problem type

The sale bin of Big Box Bargains contains n products in a row. The ith item has price ai per unit. There is no limit to the quantity of any item.

There are q customers who will enter the store to buy items. The ith customer has vi dollars, starts at item li and walks to the right to item ri (inclusive), one item at a time.

Each time they encounter an item, they will buy as many units of the item as they can afford.

You are now wondering, for each customer, how much money they will have left after buying items.

Input

The first line of input contains two space-separated integers n and q (1n,q200000).

The next line of input contains n space-separated integers ai (1ai1018).

Each of the next q lines contains three space-separated integers vi (1vi1018), li, and ri (1lirin).

Output

For each of the q customers, print, on a single line, a single integer indicating the remaining amount of money after shopping.

Sample Input

Copy
5 3
5 3 2 4 6
8 5 5
107 1 4
7 3 5

Sample Output

Copy
2
0
1
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments


  • 1
    Jinx  commented on Oct. 14, 2023, 9:43 p.m.

    nice of yall to make the very last case time out and not even give partial points 💀