Help John <HSBC>

4.1

9 votes
Basic Programming, Basics of Implementation, Easy, Implementation, Sets, Standard Template Library
Problem

You are required to collect N numbers from a bag. Initially, the bag is empty. Whenever you put a number X in the bag, then the owner of the bag asks the question.

The questions are as follows:

  • What is the greatest integer that is smaller than X and present inside the bag?
  • What is the smallest number that is greater than X and present inside the bag?

If you answer both the questions correctly, then you can put X inside the bag. Your task is to answers the questions that are asked by the owner of the bag.

Input format

  • First line: N denoting the number of integers that you want to put inside the bag
  • Next N lines: X denoting the integer that you want to put inside the bag

Output format
For every integer X, print the answers of the questions, in the form of space-separated integers, that are asked by the owner of the bag. If no such numbers exist in the bag, then print 1.

Constraints
1N1051X109

All Xs are distinct.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Initially, the bag is empty so for the first integer X=1 the answer to the first question is 1 similarly for the second question.
For X=4 the greatest number smaller than 4 is 1and there is no number greater than 4 is present in the bag So the answer to the second question will be 1.

Editor Image

?