No.135 A One-Dimensional Problem for Now
Problem Statement
There are $N$ points at integer coordinates on a number line.
Choose $2$ points among them that are not at the same coordinate, and find the distance between those $2$ points.
Letting $X_i$ be the coordinate of the $i$-th point and $X_j$ the coordinate of the $j$-th point, the distance is defined as
the absolute value $|X_i-X_j|$.
Here, suppose you choose the 2 points with the minimum distance. Find the minimum distance between the chosen $2$ points.
If it is impossible to choose $2$ points satisfying the condition, output $0$.
Input
$N$ $X_1\ X_2\ \dots\ X_N$
All inputs are given as integers.
・$1\le N \le 100000=10^5$
・$0\le X_i \le 1000000=10^6, 1\le i \le N$
Output
Output the minimum distance between $2$ points satisfying the condition.
If $2$ points cannot be chosen, output $0$.
Print a newline at the end.
Sample
Sample 1
Input
3 0 51 100
Output
49
Choosing the points at coordinates $51$ and $100$ gives the minimum distance $49$.
Sample 2
Input
4 0 1 1 0
Output
1
Points at the same coordinate may be given.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。