#C4610. Top K Popular Recipes
Top K Popular Recipes
Top K Popular Recipes
You are given a number of test cases \(T\). For each test case, you are provided with an integer \(N\) representing the number of recipes, followed by \(N\) integers which denote the popularity scores of each recipe. Note that any recipe with a negative score is considered invalid and must be excluded.
Additionally, a value \(k\) is given, representing the number of top recipes to output based on their popularity. Your task is to filter out the negative scores, sort the remaining scores in descending order, and then output the top \(k\) scores. If there are fewer than \(k\) valid recipes, output all available valid scores in descending order. Each test case result should be printed on a separate line.
inputFormat
The input begins with an integer (T), the number of test cases. For each test case, three lines are provided:
- An integer (N), the number of recipes.
- A line with (N) space-separated integers representing the popularity scores.
- An integer (k), specifying the number of top recipes to output.
outputFormat
For each test case, output one line containing the top (k) popular scores separated by a single space in descending order. If there are no valid recipes after filtering, output an empty line.## sample
2
5
-10 20 30 -5 40
3
4
50 60 -70 80
2
40 30 20
80 60
</p>