Why am I getting 'Terminated due to timeout' error here? : <p>I'm solving <a href="https://www.hackerrank.com/challenges/circular-array-rotation" rel="nofollow">this problem</a> on Hackerrank.</p>

<p>John Watson performs an operation called a right circular rotation on an array of integers, [a[0],a[ 1]......a[n]].After performing one right circular rotation operation, the array is transformed from [a[0],a[ 1]......a[n]] to [a[n- 1],a[0]......a[n-2]].</p>

<p>Watson performs this operation 'k' times. To test Sherlock's ability to identify the current element at a particular position in the rotated array, Watson asks  'q' queries, where each query consists of a single integer, 'm', for which you must print the element at index  in the rotated array (i.e., the value of a[m] ).</p>

<p>Input Format</p>

<p>The first line contains 3 space-separated integers,'n' ,'k' , and , 'q' respectively. 
The second line contains 'n' space-separated integers, where each integer      'i' describes array element a[n] (where 0&lt;=i

<p>Output Format</p>

<p>For each query, print the value of the element at index 'm' of the rotated array on a new line.</p>

<pre><code>#include &lt;cmath&gt;
#include &lt;cstdio&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */   
int n,k,q,temp;
cin&gt;&gt;n&gt;&gt;k&gt;&gt;q;       //Input of n,k,q;
int arr[n],qur[q];
for(int i=0;i&lt;n;i++)    //Input of array
{
    cin&gt;&gt;arr[i];
}
    for(int i=0;i&lt;q;i++)    //Input of query numbers
{
        cin&gt;&gt;qur[i];
}

for(int z=0;z&lt;k;z++)
{
    temp = arr[n-1];
    for(int i=n-1;i&gt;0;i--)
    {
        arr[i]=arr[i-1];
    }
    arr[0]=temp;
}

for(int i=0;i&lt;q;i++)
{
    cout&lt;&lt;arr[qur[i]]&lt;&lt;endl;
}


return 0;
 }
</code></pre>

<p>The code's logic seems to be flawless. I'm a newbie.Thanks in advance.</p>
