Print K largest element
Submissions: 329   Accuracy:

1.62%

  Max. Score:

100

Given an array A of N positive integers. The task is to find K largest elements from the array in the same order as they occur in the input array.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains two Integers N (size of the array) and K and the second line contains N space separated elements.

Output:
For each test case, print the K largest elements in new line.

Constraints:
1 <= T <= 100
1 <= K <= N <= 106
1 <= A[i] <= 105

Example:
Input:

2
5 2

5 4 2 1 2
7 5
3 4 1 2 5 7 6
Output:
5 4
3 4 5 7 6

Explanation:
Testcase 1: For elements 5, 4, 2, 1, 2 and for value K = 2. 5 and 4 are two largest elements among them and they are printed as they were in input array.


to report an issue on this page.