#C4401. Triple Array Reversal
Triple Array Reversal
Triple Array Reversal
You are given an array of integers of size \(N\) and an integer \(K\). Your task is to perform a triple reversal operation on the array. The operation works as follows:
- Reverse the first \(K\) elements (i.e., the subarray from index 0 to \(K-1\)).
- Reverse the remaining \(N-K\) elements (i.e., the subarray from index \(K\) to \(N-1\)).
- Finally, reverse the entire array of size \(N\).
For example, if \(N = 5\), \(K = 3\) and \(A = [1,2,3,4,5]\), then:
Step 1: Reverse first 3 elements: [3,2,1,4,5] Step 2: Reverse last 2 elements: [3,2,1,5,4] Step 3: Reverse the whole array: [4,5,1,2,3]
Your goal is to implement this transformation. Note that if \(K = N\) or \(K = 1\), the operations should still be correctly applied.
inputFormat
The input is read from standard input and 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 index partition.
- The second line contains \(N\) space-separated integers representing the array \(A\).
outputFormat
Output the final transformed array as \(N\) space-separated integers on a single line to standard output.
## sample5 3
1 2 3 4 5
4 5 1 2 3
</p>