title: Moving values in Array to the left/right to k positions?
body: <p>I have an array of n values. I have a value p which can be 1 or -1. I have to move the positions in the Array k positions to the left if p = 1 or to the right if p = -1.</p>
  <p>1 ≤ N ≤ 1.000.000
  0 ≤ K ≤ 1.000.000</p>
  <p>I tried:</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
  
     int n, p, k;
     int v[1000002];
     cin &gt;&gt; n &gt;&gt; k &gt;&gt; p;
  
     for ( int i = 1; i &lt;= n; i++ ) {
         cin &gt;&gt; v[i];
     }
  
     if( p == 1) {
         for ( int i = k + 1; i &lt;= n ; i++ ) {
             cout &lt;&lt; v[i] &lt;&lt; &quot; &quot;;
         }
         for ( int i = 1; i &lt;= k; i++ ) {
             cout &lt;&lt; v[i] &lt;&lt; &quot; &quot;;
         }
     }
     else {
         for ( int i = n - k + 1; i &lt;= n; i++ ) {
             cout &lt;&lt; v[i] &lt;&lt; &quot; &quot;;
         }
         for ( int i = 1; i &lt;= n - k; i++ ) {
             cout &lt;&lt; v[i] &lt;&lt; &quot; &quot;;
         }
     }
  
     return 0;
  }
  </code></pre>
  <p>The problem is I use an online tester to do tests on it to see if it applies to all possible cases, but this solution passes all but 3 tests. The results are correct, but it says that I have surpassed the time limit for the respective test. I cannot comprehend how because I only use essential code like reading and printing the array.</p>