#C877. Rotate Array

    ID: 52788 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

Given an array of integers, rotate the array to the right by (k) steps. In other words, given an array (A = [a_1, a_2, \dots, a_n]) and a non-negative integer (k), return a new array where the last (k) elements of (A) are moved to the front, and the remaining elements are shifted to the right. Note that (k) should be taken modulo (n) (i.e. (k = k \mod n)), so that if (k) is greater than (n), the rotation still works correctly.

Your task is to implement this rotation. The input will be read from standard input and the output should be printed to standard output.

inputFormat

The input consists of two lines:

  • The first line contains two integers (n) and (k) separated by a space, where (n) is the size of the array and (k) is the number of positions to rotate the array.
  • The second line contains (n) space-separated integers, representing the elements of the array.

outputFormat

Output the rotated array as a single line of (n) integers separated by spaces.## sample

5 2
1 2 3 4 5
4 5 1 2 3