Given an input stream of **n** integers, find the k^{th} largest element for each element in the stream.

**Input:**

The first line of input contains an integer **T** denoting the number of test cases. Then T test cases follow. Each test case contains two lines. The first line of each test case contains two space separated integers **k** and **n** . Then in the next line are **n** space separated values of the array.

**Output:**

For each test case, in a new line, print the space separated values denoting the **k ^{th}** largest element at each insertion, if the

**Constraints:**

1 <= T <= 100

1 <= K <= n

1 <= n <= 10^{6}

1 <= stream[] <= 10^{5}

**Example:
Input:**

2

4 6

1 2 3 4 5 6

1 2

3 4

**Output:**

-1 -1 -1 1 2 3

3 4

**Explanation:
Testcase1:**

k = 4

For 1, the 4th largest element doesn't exist so we print -1.

For 2, the 4th largest element doesn't exist so we print -1.

For 3, the 4th largest element doesn't exist so we print -1.

For 4, the 4th largest element is 1 {1, 2, 3, 4}

For 5, the 4th largest element is 2 {2, 3, 4 ,5}

for 6, the 4th largest element is 3 {3, 4, 5}

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

praneethmamidala83 | 583 |

pallavimanukonda8 | 563 |

a8haysingh | 451 |

vraamg | 432 |

RajatGarg5 | 386 |

descifrador | 1683 |

mantu_singh | 1520 |

rishabh2017 | 1273 |

gladiator121 | 1268 |

kid_kb | 1264 |

blackshadows | 5362 |

Ibrahim Nash | 5244 |

akhayrutdinov | 5111 |

mb1973 | 4974 |

Quandray | 4732 |

Login to report an issue on this page.