Problem Statement
You are given a list of integers . Now, imagine you have a list of all pairings of integers from to such that is sorted in increasing order. In other words, you have:
\begin{array}{rcc} P &=& \Big[\ \normalsize(1, 1), (1, 2), (1, 3), ..., (1, n),\ & & \ \ \ (2, 1), (2, 2), (2, 3), ..., (2, n), \ & & \ ...\ & & \ \ \ \ \ \ (n, 1), (n, 2), (n, 3), ..., (n, n)\ \Big]\normalsize \ \end{array}
Now, you are given queries, each will contain a single integer such that , given some you should determine :
\begin{array}{rcl} f(k) &=& \sum_{i=1}^{k} x_{P_i[0]} - x_{P_i[1]} \end{array}
In other words, takes the first pairs in , and for each pair it will calculate and sum all of them together.
Input Format
Your first line will contain two space-separated integers and
Your next line will contain space-separated integers through .
Your next lines will contain one integer each, the of which representing .
Output Format
You should output a single integer for each query (in the same order the queries appear), the of which should be .
Constraints
Sample Cases
Input 1
3 3
11 7 5
4
6
9
Output 1
6
8
0
Explanation 1
Here .
For the first query , we calculate . For the second query , we calculate . For the third query , we calculate .
Input 2
10 5
-5 10 -1 9 -4 6 3 -1 -7 -5
20
36
8
79
38
Output 2
40
64
-57
126
80
Template
n, q = map(int, input().split())
numbers = list(map(int, input().split()))
queries = [int(input()) for _ in range(q)]
# print your output
Comments