Question
Candy Queue
Lila has candies of varying sizes, each with a specific count. Students are lined up, and candies are distributed one per student in non-decreasing size order.
Given the position Q of a student in the line, determine the size of the candy they receive, or output -1 if they get none.
Input
The first line of the input contains two space-separated integers N and Q.
The second line of the input contains N space-separated integers Ai, the size of ith candy.
The third line of the input contains N space-separated integers Bi, the count of ith candy.
The second line of the input contains N space-separated integers Ai, the size of ith candy.
The third line of the input contains N space-separated integers Bi, the count of ith candy.
Output
Find the size of the candy the student at position Q will receive. If the student doesn't receive any candy, print -1.
Example
Sample Input
5 10
1 2 3 4 5
1 2 3 4 5
Sample Output
4
Sample Explanation
The first candy is given to the first student.
The next candy, which is of size 2, is given to the next 2 students.
The third candy, of size 3, is given to the next 3 students.
Similarly, the next 4 students receive candy of size 4.
The total number of students is 1 + 2 + 3 + 4 = 10.
Thus, the 10th student receives candy of size 4.
5 10
1 2 3 4 5
1 2 3 4 5
Sample Output
4
Sample Explanation
The first candy is given to the first student.
The next candy, which is of size 2, is given to the next 2 students.
The third candy, of size 3, is given to the next 3 students.
Similarly, the next 4 students receive candy of size 4.
The total number of students is 1 + 2 + 3 + 4 = 10.
Thus, the 10th student receives candy of size 4.