Find the K-th Tastiest Food 1
Time limit1sMemory limit512 MB
Given two sorted arrays of tastes, answer queries asking for the k-th smallest value among the first i Korean and first j Western dishes and report which array and index it came from.
- Level
Medium7 of 10
- Topics
- Binary search, Divide and conquer, Sorting, Array
- Solved
- No attempts yet
Problem
Seojun loves Korean food and Western food alike. One day his father gave hungry Seojun N Korean dishes and N Western dishes. After eating every dish, Seojun rated the taste of each one. A dish's taste is a positive integer no greater than , and a smaller value means a tastier dish.
His father gave Seojun queries asking for the k-th tastiest dish among Korean dishes and Western dishes , but Seojun was so full that he fell asleep. Print the answers to the queries on his behalf.
Input
The first line gives the number of dishes, N.
The next line gives the tastes of the N Korean dishes () in ascending order.
The next line gives the tastes of the N Western dishes () in ascending order.
The next line gives the number of queries, Q. The following Q lines each give a query i j k. ()
Output
Print the answer to each query on its own line, for Q lines total. Each answer is the type of the dish (1 for Korean, 2 for Western) and the dish's index, separated by a space.
Constraints
- All dishes have distinct tastes.