spoj#CATINV. Cats Invitation
Cats Invitation
In Kutus and Putus’ first marriage anniversary, they planned to invite all of their cat friends. So they invited all cats in a hall room. Due to business, all of the cats couldn’t attend the party at the same time. Different cats attended party at different times and some of them couldn’t stay till the end. Kutus wanted to make Putus as much happy as possible. If at any moment, there were ‘L’ cats present in the hall room, then happiness level of Putus were ‘L’ at that moment. Now Kutus gave you a list of every cats’ arrival and departure time at the party and asked you few queries: Maximum time segment where the happiness level of Putus was ‘L’.
Input
Input starts with an integer T, which denotes the number of test cases. Each case contains 2 space separated integer N and Q denoting the number of cats came to the party and the number of queries to be performed. Next line contains N space separated integers ‘X’ and ‘Y’ denoting the arrival time and departure time of ith cat. Each of the next Q lines contains an integer ‘L’ as described above.
Output
For each case print the case number and print the time segment ‘X’ & ‘Y’ that is Putus’ level of happiness. If there are multiple solution, print the time segment that comes earliest. If there is no possible answer, print -1.
Constraints:
T <= 10
1 <= N <= 100000
1 <= Q <= 100000
1 <= Xi <= Yi <= 100000
1 <= L <= 100000
Example
Input:1
5 5
1 2
2 3
1 3
2 4
3 5
1
2
3
4
5
Output:Case 1:
4 4
1 1
2 2
-1
-1