Define the ugliness of a $$\textbf{set}$$ $$T$$ as the number of unordered pairs $$(x,y)$$ such that $$x,y \in T$$ and $$x + y > D$$. Given a set $$S$$ of length $$M$$, find the lexicographic minimal subset of $$S$$ of length $$N$$ such that the ugliness of this subset is minimal.
Suppose we have two different sets $$A$$ and $$B$$ of length $$K$$ with elements $$a_1 < a_2 < \dots < a_K$$ and $$b_1 < b_2 < \dots < b_K$$ respectively. We say that $$A$$ is lexicographically smaller than $$B$$ if there exist $$i$$ such that $$a_j = b_j$$ for $$1 \le j < i$$ and $$a_i < b_i$$.
$$\textbf{Input}$$
The first line contains three integers $$N, M, D$$ $$(1 \le N \le M \le 10^5, 1 \le D \le 10^9)$$.
The second line contains $$M$$ $$\textbf{distinct}$$ integers representing the set $$S$$. All elements of $$S$$ are between $$1$$ and $$10^9$$ (inclusive).
$$\textbf{Ouput}$$
Output the subset of minimal ugliness in the order given in input. Because all elements are distinct there will always be only one way of printing them.
The ugliness of this subset is equal to $$9$$, the pairs are $$(2,3), (3,4), (2,4), (2,2), (3,3), (4,4), (1,2), (1,3), (1,4)$$.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor