Help John <HSBC>
Practice
4.1 (9 votes)
Basic programming
Basics of implementation
Easy
Implementation
Sets
Standard template library
Problem
83% Success 5484 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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
\(1 \leq N \leq 10^5\\1 \leq X \leq 10^9\)

All \(Xs\) are distinct.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
Ad-HocBasic ProgrammingEasy
Points:20
67 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:20
23 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyException handlingImplementationjava