Numbers O Numbers

5

1 votes
Implementation, Binary Search, Medium
Problem

Arjun and Ranveer are best friends. Now, they are in a problem and you being the wisest programmer of all, have decided to help them. They both have brought you an array of integers and you have to help them by telling the the minimum possible maximum number of a non-decreasing sequence of length X.

INPUT- Input consists of number of test cases T Each test case contains size of array i.e N. Next line contains N space separated elements of array. Next line contains length of the non decreasing sequence i.e. X.

OUTPUT- You have to print the answer to their query and if not possible output "-1"

CONSTRAINTS- 1≤T≤100

1≤N≤10^6

1≤a[ i ]≤10^6

1≤X≤N

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Explanation

In sample input, possible non-decreasing sequences of length X = 3 are (9,11,12),(7,11,12),(2,5,11),(2,4,11),(2,5,12),(2,4,12),(2,11,12),(5,11,12),(4,11,12) and the minimum possible maximum number is 11 for the sequences (2,5,11) and (2,4,11). Hence, the answer is 11.

Editor Image

?