The Close-i-ness
Practice
2.5 (2 votes)
Easy
Problem
86% Success 696 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Abhisek likes to play with numbers. One day, he was solving math puzzles and he came across an interesting problem.

A sorted list of N numbers are given and a number Num. We have to find the five numbers that are closest (numerically) to Num. A number x in the array is closest to Num if |Num-­x| is the smallest among all such x possible.

Note: If the Num is present in given list, then it should be in the output.

Constraints:

5 < N <20

­1 <Num< 10000

Input:

First input line consists of 2 integers N followed by Num

Second input line consists of N integers m1 m2 m3 .. mN denoting the numbers given in the list.

where mi's are N numbers in sorted order.

Output:

p1 p2 p3 p4 p5

where pi's are closest numbers in increasing order of absolute difference from Num. If there are two numbers with same difference, print the larger one first.

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
836 votes
Tags:
Ad-HocSimulationEasyMathematicsOpenApprovedMathamatics
Points:20
3 votes
Tags:
Easy
Points:20
Tags:
MathematicsEasyMathematicsMathamatics
Editorial

No editorial available for this problem.