We know that $$$a_1=a_2−a_3+a_4−a_5+⋯+a_{2n}−a_{2n+1}$$$. The equation can be transformed to $$$a_1+a_3+⋯+a_{2n+1}=a_2+a_4+⋯+a_{2n}$$$, meaning that the sum of all odd-indexed elements in the array a equals to that of all even-indexed ones.
There are $$$n+1$$$ elements in the left formula and n in the right of the equation above. Therefore, if we choose the largest $$$n+1$$$ elements of the given array $$$b$$$ as all the odd-indexed elements and the rest for the even-indexed, indicating the lost element is with an even index in $$$a$$$, the sum of odd-indexed elements is, beyond no doubt, larger than the sum of the even-indexed ones (the lost element excluded of course), ensuring that the lost element is positive. Any of odd-indexed elements, also, will be larger than all the even-indexed ones other than the lost element (in other words, $$$a_{2i}<a_{2j−1}$$$ where $$$i$$$ and $$$j$$$ are integers). Suppose the element lost is $$$a_2$$$, and think about whether $$$a_2$$$ is bound to be larger than the largest element of $$$b$$$ (let's index the odd-indexed elements in the order of $$$a_1>a_3>⋯>a_{2n+1}$$$). The given equation can be transformed to be $$$a_2=a_1+(a_3−a_4)+(a_5−a_6)+⋯+(a_{2n−1}−a_{2n})+a_{2n+1}$$$, thus it can be reached that $$$a_2>a_1$$$ because of $$$a_{2i−1}−a_{2i}>0$$$ mentioned in our considerations in the paragraph above, which means the lost element IS the largest element of $$$a$$$, securing the pairwise distinct highlighted by the problem.
So what we need to do is just sort the array $$$b$$$, index the $$$n+1$$$ largest elements of $$$b$$$ with odd numbers and the rest with even numbers in $$$a$$$, and calculate out the lost element $$$a_2$$$.
But scarcely when the contest was only one single minute away from finishing had I reached this aha moment :(
public static void solve() throws Exception {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
long[] b = new long[2 * n];
for (int i = 0; i < 2 * n; i++) {
b[i] = scanner.nextLong();
}
Arrays.sort(b);
long lostElement = 0;
for (int i = 0; i < n - 1; i++) {
lostElement -= b[i];
}
for (int i = n - 1; i < 2 * n; i++) {
lostElement += b[i];
}
System.out.print(b[2 * n - 1] + " " + lostElement + " ");
for (int i = 0; i < n - 1; i++) {
System.out.print(b[2 * n - i - 2] + " " + b[i] + " ");
}
System.out.println(b[n - 1]);
}
I'm sorry I made a mistake when making edits to the previous blog featuring the same contents with this one, having deleted the issued-2-days-ago one unintentionally. This blog is just a backup, so you don’t need to vote if you take it good.