#K9586. Treasure Distribution

    ID: 38957 Type: Default 1000ms 256MiB

Treasure Distribution

Treasure Distribution

You are given nn castles and mm knights. Each castle contains a certain amount of treasure. Every knight is assigned a segment represented by two integers ll and rr, indicating the range of consecutive castles (1-indexed) that the knight can protect. Your task is to calculate the total amount of treasure each knight can protect, i.e. the sum of the treasures in the castles from index ll to rr.

For example, if there are 5 castles with treasures [1, 3, 2, 5, 4] and a knight protects castles 1 to 3, then the total treasure for that knight is 1+3+2=61+3+2=6.

inputFormat

The input is read from standard input (stdin). The first line contains two integers nn and mm, representing the number of castles and knights respectively. The second line contains nn space-separated integers indicating the treasure in each castle. This is followed by mm lines where each line contains two integers ll and rr, representing the segment (inclusive) that a knight can protect.

outputFormat

Output to standard output (stdout) exactly mm lines. The ii-th line should contain a single integer representing the total treasure that the ii-th knight can protect.## sample

5 3
1 3 2 5 4
1 3
2 4
1 5
6

10 15

</p>