A toll plaza keeps a ledger of n daily receipts, one integer per day (a negative value means net refunds outweighed receipts that day). You must answer q independent queries. Each query gives two day numbers l and r (1-indexed, inclusive) and asks for the total of all receipts from day l through day r.
Line 1: an integer n.
Line 2: n space-separated integers, the daily receipts in day order.
Line 3: an integer q.
Next q lines: two integers l and r.
Print q lines. Line i is a single integer: the total receipts for query i, in the order the queries are given.
Example 1
Input
5 3 -1 4 1 5 2 1 3 2 5
Expected
6 9
Explanation
Query 1 sums days 1..3: 3 + (-1) + 4 = 6. Query 2 sums days 2..5: (-1) + 4 + 1 + 5 = 9.
Example 2
Input
4 7 7 7 7 1 1 4
Expected
28
Explanation
The single query sums the whole ledger: 7 + 7 + 7 + 7 = 28.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →