Mean Problem

All submissions for this problem are available.
You are given a sequence $a$ and its first $n$ elements. The $i$th element of the sequence, where $i > n$ is generated by the following formula. The $i$th element $i > n$ would be the floor of the mean of last $n$ elements of the sequence. Formally, $$a_i = \lfloor \frac{\sum_{k=0}^{n1} a_{in+k}}{n} \rfloor$$ For example, $$ a_{n+1} = \lfloor \frac{a_1 + a_2 + .. + a_{n}}{n} \rfloor$$ $$ a_{n+2} = \lfloor \frac{a_2 + a_3 + .. + a_{n+1}}{n} \rfloor$$ $$ a_{n+3} = \lfloor \frac{a_3 + a_4 + .. + a_{n+2}}{n} \rfloor$$ You have to answer many queries in which you would be asked to tell some xth element of the sequence, where $x$ would be provided in the query. ###Input:  First line will contain $T$, number of testcases. Then the testcases follow.  First line of each test case contains an integer $n$.  The second of each test case contains $n$ space separated integers where $i$th of which denotes value of $a_i$.  The third line contains an integer $Q$ denoting the number of queries.  Each of the next $Q$ lines contains an integer $x$, denoting that you should tell what's the $x$th element of sequence. ###Output: For each query, output an integer denoting the value of the corresponding element of the sequence. ###Constraints  $1 \leq T \leq 10$  $1 \leq n \leq 10^3$  for $1 \leq i \leq n, 1 \leq a_i \leq 10^3$  $1 \leq Q \leq 10^5$  $1 \leq x \leq 10^9$ ###Sample Input: 1 3 2 2 3 3 1 3 4 ###Sample Output: 2 3 2 ### Explanation The 4th element of the array would be $$\lfloor \frac{2+2+3}{3} \rfloor = \lfloor \frac{7}{3} \rfloor = 2$$Author:  dpraveen_adm 
Editorial  https://discuss.codechef.com/problems/MEANPROB 
Tags  adhoc, basicmath, dpraveen_adm, simple 
Date Added:  13122019 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 