Sherlock and Numbers
Practice
3.9 (86 votes)
Approved
Binary search
Easy
Open
Sorting
Problem
55% Success 27293 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code
Watson gives to Sherlock a bag of numbers [1, 2, 3 ... N] and then he removes K numbers A1, A2 ... AK from the bag. He now asks Sherlock to find the P'th smallest number in the bag.
Input
First line contains T, the number of test cases. Each test case consists of N, K and P followed by K integers in next line denoting the array A.
Output
For each test case, print P'th smallest number in the bag. If no such number exists output -1.
Constraints
1 ≤ T ≤ 10
20% testdata: 1 ≤ N ≤ 103
20% testdata: 1 ≤ N ≤ 105
60% testdata: 1 ≤ N ≤ 109
0 ≤ K ≤ min(N, 105)
1 ≤ P ≤ N
Note: Large input files. Use scanf instead of cin.
Submissions
Please login to view your submissions
Similar Problems
Points:20
13 votes
Tags:
AlgorithmsBinary SearchEasySearchingsearching
Points:20
536 votes
Tags:
Binary SearchData StructuresEasySearching
Points:30
13 votes
Tags:
Graph TheoryApprovedMediumShortest path problem
Editorial