Series Sum

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.8s
Memory limit: 64M

Author:
Problem types

You are given a series of numbers. You are to process some queries to get the sum of all numbers in the series from 1 to and including k_i.

Subtask 1

For 3 of the 5 available points, k \le 100.

Input Specification

The first line contains n (1 \le n \le 100\,000) representing how many numbers are in the series.
The next line contains n space separated integers representing the numbers n_i (1 \le n_i \le 10\,000) in the series in order.
The next line contains k (1 \le k \le 100\,000) representing how many queries you are required to process.
The last line contains k space separated integers, k_i (1 \le k_i \le n) representing the ending index of the range you must get the sum of where the first number is at index 1.

Output Specification

For each query, output on a new line the sum of all numbers in the series from index 1 (the first number) to and including index k_i.

Sample Input

3
3 2 7
2
1 3

Sample Output

3
12

Comments

There are no comments at the moment.