Find the subset

3.5

23 votes
Sorting, Quicksort, Data Structures, Algorithms, Easy, Mathematics
Problem

Define the ugliness of a set T as the number of unordered pairs (x,y) such that x,yT 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 a1<a2<<aK and b1<b2<<bK respectively. We say that A is lexicographically smaller than B if there exist i such that aj=bj for 1j<i and ai<bi

Input

The first line contains three integers N,M,D (1NM105,1D109).

The second line contains M distinct integers representing the set S. All elements of S are between 1 and 109 (inclusive).

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.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

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).

Editor Image

?