Problem list
Log in
#coci00506 · COCI 2018/2019 Contest 3

Pismo

Silver V 1.0 s 64 MB

1 $s / 64$ $MB / 70$ points

In a small village besides Đakovo lives Kasap. While agriculture is his branch, love and destiny, in his

free time Kasap solves tasks in competitive programming and is doing very well. Particularly

interesting are the tasks involving data structures.

On a sunny summer day, Kasap's friend Mirko sent him a letter we carry forward entirely:

“My dear Kasap, I hope you tolerate well these hot summer days. I'm writing this letter because I have a problem. One friend gave me a hard task the other day that I have not managed to solve yet. Since I know that

you love this sort of tasks, I would ask you for help because I do not want to embarass myself in front

$of$ $my$ friend. In the task there is an array A consisting of N integers. You should find an interval of the

minimum value. The value $of$ the interval [L, R] $is$ defined $as$ the difference between the maximum

and minimum value ​$of$ the numbers in that interval: max(A[L], A[$L+1$], ..., A[R]) - min(A[L], A[$L+1$], ...,

A[R]). I will remind you that we observe only the intervals in which L is strictly less than R. Thank you, Mirko”

After a week of solving, Kasap has not yet managed to solve the task and asks you to help him.

Input

In the first line of input there is a positive integer ​$N$ ​(2 ≤ ​$N$​ ≤ 100 000). In the second line of input there are ​$N$​ integers, which absolute value is less than 10​^{9}^{​}.

Output

Print the minimum value of an interval.

Constraints

In the test samples worth 20 points it will hold ​$N$​ ≤ 100. In the test samples worth 40 points it will hold ​$N$​ ≤ 2 000.

Example 1

Input
2
1 3

3
1 1 1

5
1 2 1 2 1
Output
output
output
2

0

1

Explanation of the third test sample: The maximum at interval [1, 5] is 2, while the minimum on the same interval is 1, so the value of that interval is

2 - 1 = 1, which is also the minimum possible value of an interval.

Source
COCI 2018/2019 Contest 3
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code