#C14532. Pivot and Sort Arrays
Pivot and Sort Arrays
Pivot and Sort Arrays
Given an array of integers and a pivot value \(P\), rearrange the array into two lists:
- One list containing all elements less than or equal to \(P\).
- Another list containing all elements greater than \(P\).
The relative order of the elements should be preserved in each resulting list.
inputFormat
The first line contains an integer \(n\) indicating the number of elements in the array.
The second line contains \(n\) space-separated integers representing the array.
The third line contains an integer representing the pivot value \(P\).
outputFormat
Output two lines:
- The first line contains the elements less than or equal to \(P\), separated by spaces. If no such element exists, print an empty line.
- The second line contains the elements greater than \(P\), separated by spaces. If no such element exists, print an empty line.
7
10 5 2 7 3 8 4
5
5 2 3 4
10 7 8
</p>