
You are given the ratings of n coders in an array. To create effective teams, you want to form pairs of coders who have similar ratings. The strategy is to sort all the coders by their rating and then pair up adjacent coders.
Your task is to determine if it's possible to pair up all n coders. This is only possible if n is an even number.
The first line contains a single integer N, the number of coders.
The second line contains N space-separated integers, representing the ratings of the coders.
If N is even, print N/2 lines, where each line contains a pair of ratings (the two numbers in the pair separated by a space). The pairs should be printed in increasing order of their ratings.
If N is odd, print a single line with the value -1.
The core of the problem lies in sorting the initial array to bring coders with similar ratings next to each other.
6
1200 1500 1250 1300 1550 1350
1200 1250
1300 1350
1500 1550
The ratings are sorted: [1200, 1250, 1300, 1350, 1500, 1550].
Adjacent elements are paired: (1200, 1250), (1300, 1350), (1500, 1550).
These pairs are printed, one per line.
5
100 200 300 400 500
-1
The number of coders is 5 (odd). It is impossible to form pairs with all coders, so the output is -1.
The expected time complexity is O(N log N).
1 <= N <= 10^5
-10^9 <= rating <= 10^9
Time limit: 1 sec