Find the subset
Practice
3.5 (23 votes)
Sorting
Quicksort
Data structures
Algorithms
Easy
Mathematics
Problem
79% Success 3382 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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.

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
No similar problems found