#C10465. Reverse First K Elements of a Queue

    ID: 39673 Type: Default 1000ms 256MiB

Reverse First K Elements of a Queue

Reverse First K Elements of a Queue

You are given a queue of integers and an integer K. Your task is to reverse the order of the first K elements of the queue while leaving the remaining elements in their original order. In mathematical terms, given a sequence (a_1, a_2, \ldots, a_N) and an integer (K) (with (K \leq N)), you need to transform the sequence into (a_K, a_{K-1}, \ldots, a_1, a_{K+1}, \ldots, a_N). For example, if the input queue is [10, 20, 30, 40, 50] and (K=3), then the output should be [30, 20, 10, 40, 50]. The input will be taken from standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line contains an integer (N), representing the number of elements in the queue. The second line contains (N) space-separated integers which comprise the queue. The third line contains an integer (K), the number of elements from the front of the queue to be reversed.

outputFormat

Print the resulting queue as a single line of space-separated integers after reversing the first (K) elements.## sample

5
10 20 30 40 50
3
30 20 10 40 50