PEG 11/12 Programming Test 1 - October 19

Problem 4: Cyclopian Census

FurWear is running out of oxygen!

After an emergency meeting between the Oelfinn and FurWear, and the ingestion of Earth-imported beer, the Oelfinn have decided to contract FurWear to perform analysis on their most recent census data (which now includes Oelfinn living on other planets). The Oelfinn wish to find how old the ith oldest Oelfinn is.

Due to their abnormally long lifespans and quirky reproductive cycles, it is guaranteed that no two Oelfinn will be the same age.

Input

The first line consists of a single integer N (1 < N ≤ 60 000), the number of live Oelfinn. The following N lines each contain a single integer ai (10 ≤ ai ≤ 1 000 000), the age of the ith Oelfinn (in millenia). The next line consists of a single integer Q (1 ≤ Q ≤ 100), the number of queries to follow. The following Q lines each contain a single integer qi (1 ≤ qi ≤ N), the ith query.

Output

Output the correct answer to each query in the order given, on separate lines.

Sample Input

10
42
23
15
52
63
24
73
54
66
10
3
1
5
10

Sample Output

10
42
73

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 17, 2011
Author: jargon

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

why is 42 outputted in the sample output?

The first line tells you how many Oelfinn there are. In the sample case, there are 10.

Immediately following that is the number of queries. Here, it's 3. The queries specify that you are to output the ages of the 1st, 5th, and 10th ones.

In order their ages are:
10, 15, 23, 24, 42, 52, 54, 63, 66, 73

Hence you are to output 10, 42, 73.

Edit: I now realise a possible source of your confusion: the statement says to print the ith oldest, and yet the problem actually requires you to output the ith youngest. Somehow this hasn't been caught in the 5.5 intervening years! I will correct this soon.