# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# Min Value

By robin_aust · Limits 1s, 512 MB

You are given an array of $N$ integers and q queries. In each query you are given an integer value $x$. For each $x$ you have to choose a value from the given array. Let, this value be $y$. Now your task is to find the minimum value of $z$. Where,

$z = max(x, y) - min(x, y)$

$max(x, y)$ means maximum value between $x$ and $y$.

$min(x, y)$ means minimum value between $x$ and $y$.

## Input

First line contains two integers $N$ ($1 ≤ N ≤ 10^5$) and $q$ ($1 ≤ q ≤ 10^5$). The next line contains $N$ space separated integers, $a_i$ ($0 ≤ a_i ≤ 10^9$), forming this array. Next $q$ lines will contain the value of $x$ ($0 ≤ x ≤ 10^9$).

## Output

For each $x$ you have to print a line containing the minimum value of $z$.

## Sample

InputOutput
5 2
2 1 6 4 5
1
3

0
1


### Statistics

62% Solution Ratio

Debasish161017Earliest, Dec '20

user.299687Fastest, 0.0s

zahid_hasanLightest, 1.2 MB

shreasShortest, 520B

Login to submit

### Related Contests

 NCPC Team Selection Contest of IU - 2021 9M ago STP Coding Test 31 Dec 2020 Dec '20
Toph uses cookies. By continuing you agree to our Cookie Policy.