Cheema and stations

0

0 votes
Easy
Problem

Cheema is travelling in train with Vishal and Nimit. Kandoria who cares a lot about his friends, wants to know about their positions from the origin. During the journey he calls Cheema multiple times and asks him about how far have they reached and tell the distance from origin. You are given distance of stations from origin.  During a call from Kandoria Cheema has to tell the station's distance from the origin if they are  currently on a particular station, else he has to tell the distance of the last station and the upcomming station.

 

At the time Kandoria calls Cheema doesn't know his exact distane but he knows the distance of last station and upcoming station. So he will tell the distance of last station and next station if they are in between two stations.

Input:

First line would contain N - number of elements in an array.
Second line would contain Ai - N space -separated integers which would be in sorted order - the distance of stations from origin.
Next line would contain Q - no of times Kandoria will call Cheema.
Next line would contain Di - Q space-separated integers the distance of the train at the time Kandoria calls.

Output:
if the train is at a particular station then print only the station. else print the distance of two surrounding stations which are space-separated.

Constraints:
1 <= N <= 105
1 <= Ai <= 109
1 <= Q <= 105
1 <= Di <= max(Ai)

 

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?