#C11963. Array Rearrangement via Permutation
Array Rearrangement via Permutation
Array Rearrangement via Permutation
You are given an array of integers and a permutation array. The permutation array is a rearrangement of the indices from \(0\) to \(N-1\), where \(N\) is the number of elements in the array. Your task is to rearrange the original array so that for each index \(i\) in the original array, its value is placed at index \(perm[i]\) in the resulting array.
Example:
Input: 5 10 20 30 40 50 4 3 2 0 1</p>Output: 40 50 30 20 10
In the above example, the element \(10\) at index \(0\) moves to index \(4\), \(20\) moves to index \(3\), \(30\) moves to index \(2\), and so on.
Note: All arrays use 0-based indexing.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(N\), representing the number of elements in the array.
- The second line contains \(N\) space-separated integers representing the original array.
- The third line contains \(N\) space-separated integers representing the permutation array.
outputFormat
Output a single line to standard output (stdout) with the rearranged array. The numbers should be printed as space-separated integers.
## sample5
10 20 30 40 50
4 3 2 0 1
40 50 30 20 10