Finding the K-th Tasty Food 2
Time limit2sMemory limit512 MB
Given three sorted arrays and queries (x, y, z, k), find the k-th smallest value among the first x, y, and z elements and report which array and index it came from.
- Level
Hard8 of 10
- Topics
- Binary search, Divide and conquer, Array, Sorting
- Solved
- No attempts yet
Problem
Seojun loves Korean, Western, and Chinese food. One day his father gave hungry Seojun N Korean dishes, N Western dishes, and N Chinese dishes. After eating every dish, Seojun rated the taste of each one. A dish's taste is a positive integer less than or equal to , and a smaller value means a tastier dish.
His father gave Seojun queries asking for the k-th tastiest dish among Korean[1..x], Western[1..y], and Chinese[1..z]. Seojun was too full and 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 tastes () of the N Chinese dishes in ascending order.
The next line gives the number of queries Q. The following Q lines each give a query x y z k. ()
Output
Print the answer to each query on Q lines. For each query, print the type of dish (Korean 1, Western 2, Chinese 3) and the dish's index, separated by a space.
Constraints
- All 3N dishes have distinct tastes.