Optimised solution for DE shaw coding round problem

You are working in a team. Your team is continuously assigned with different tasks at different intervals of time. Each task has a complexity level associated with it. Whenever you are assigned a task, your curious manager gives a number k along with the task. He wants you to find the kth task if all the tasks (including the current task) are sorted in increasing order of their complexities. You are given an array ‘tasks’ of size n, denoting the complexity of different tasks assigned to the team at different time intervals and an array k of size n, denoting the k number associated with each task assigned.

Input Format

The first line contains an integer n.

Next n lines contain an integer corresponding to

tasks[i].

Next line contains an integer n.

Next n lines contain an integer corresponding to k[i].

Output Format

Output n lines denoting the answer.

Constraints

1 <= N <= 10^5

-10^9 <= tasks[i] <= 10^9

1 <= k[i] <= i

** Anyone knows how to solve it ?