#C4609. Merge and Sort Two Lists by Custom Rule
Merge and Sort Two Lists by Custom Rule
Merge and Sort Two Lists by Custom Rule
You are given two lists of integers. Your task is to merge these two lists into one list and then sort the merged list based on the following rules:
- The list must be sorted in descending order based on the integer values.
- If two elements are equal, the element that came from the first list should appear before the element from the second list.
Mathematically, if we denote an element as \(a_i\) and use an indicator \(d\) where \(d=1\) means the element comes from the first list and \(d=2\) if it comes from the second list, then the sorting order is defined by the following:
Sort by \(-a_i\) as the primary key and by \(d\) as the secondary key (in ascending order).
The input is given via standard input (stdin) and the output should be written to standard output (stdout) where the merged and sorted list is printed in a single line with each integer separated by a space.
inputFormat
The input consists of two lines:
- The first line contains a space-separated list of integers representing the first list. If the list is empty, this line will be empty.
- The second line contains a space-separated list of integers representing the second list. If the list is empty, this line will be empty.
You should read from standard input.
outputFormat
A single line containing the merged and sorted list. The integers should be separated by a single space. Print the output to standard output.
## sample9 2 5 7
3 6 2 7
9 7 7 6 5 3 2 2