#K58532. Sort Persons by Height and Chocolates
Sort Persons by Height and Chocolates
Sort Persons by Height and Chocolates
You are given two lists representing the attributes of several persons. The first list A
contains the heights of the persons, and the second list B
contains the number of chocolates they possess. Your task is to sort the persons primarily by their height in descending order. In case two or more persons have the same height, they should be sorted by the number of chocolates in ascending order.
Sorting criteria:
- If h1 > h2, then the person with height h1 comes before the person with height h2.
- If h1 = h2, then the person with fewer chocolates comes first.
The result should be printed as a list of pairs, where each pair is a person represented by their height and the corresponding number of chocolates. Each pair must be output on a separate line, with the two numbers separated by a space.
Example:
Input: 4 170 180 160 170 2 7 10 3</p>Output: 180 7 170 2 170 3 160 10
inputFormat
The input from stdin consists of three lines:
- An integer n, representing the number of persons.
- A line containing n space-separated integers representing the heights (list A).
- A line containing n space-separated integers representing the number of chocolates (list B).
outputFormat
Print the sorted list of persons on stdout. For each person, output a line with two integers: the height and the number of chocolates, separated by a space.## sample
4
170 180 160 170
2 7 10 3
180 7
170 2
170 3
160 10
</p>