eolymp
bolt
Try our new interface for solving problems
Problems

Big sorting

Big sorting

Given an array $a_1, a_2, ..., a_n$ of $n$ integers. Sort it in ascending order. Then answer $q$ queries: for each input value $k$ print $a_k$. \InputFile The first line contains the size $n~(n \le 10^6)$ of array and the number of queries $q~(q \le 10^5)$. The second line contains the array elements $a_1, a_2, ..., a_n$. Each of the following $q$ lines contains a query: one integer $k~(1 \le k \le n)$. \OutputFile For each query print $a_k$ on a separate line: the $k$-th number in the sorted array. \Examples Sort the numbers in the given sample: \includegraphics{https://eolympusercontent.com/images/n56qrbm0p9383afofejfr5avck.gif} The answers to the queries are: $a_4 = 5, a_5 = 6, a_1 = 1, a_7 = 7, a_2 = 1$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
10 5
10 1 7 5 9 6 8 2 1 6
4
5
1
7
2
Output example #1
5
6
1
7
1