시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 433 | 336 | 258 | 81.905% |
Suppose we have an array of integers such as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. It is easy to compute the sum of all its elements. We only need a loop! For example:
int size = 10; int total = 0; for (int i = 0; i < size; i += 1) { total = total + v[i]; }
If we want to count a different range of elements (for example, from position 5 to 7) we only need to change a few parts of the loop. In this problem you'll have to do this operation several times!
The first line of the input will contain an integer n (the array size). The next line will contain n integers separated by spaces.
After the array, the next line will contain an integer m (the number of tests). The next m lines will contain a test each. A test is a pair of integers start, end. You'll have to compute the sum of the elements from the position start to end.
Limits
For each test, print the sum of the elements of the array from the position start to the position end inclusive.
That is: array[start] + array[start+1] + ... + array[end-1] + array[end].
10 1 5 6 3 5 9 0 3 9 1 5 1 1 0 9 5 7 9 9 1 8
5 42 12 1 40