#P7314. [COCI 2018/2019 #3] Pismo

[COCI 2018/2019 #3] Pismo

Description

You are given an array AA containing NN integers.

For an interval [L,R][L,R] in this array (L<RL \lt R), its value is defined as $\max(A[L],A[L+1],\cdots,A[R])-\min(A[L],A[L+1],\cdots,A[R])$.

Find the minimum value among all interval values in the array.

Input Format

The first line contains a positive integer NN.

The second line contains NN integers AiA_i, representing the numbers in the array.

Output Format

Output the minimum value among all interval values.

2
1 3
2
3
1 1 1
0
5
1 2 1 2 1
1

Hint

Explanation for Sample 3

A valid interval is [1,5][1,5]. The value of this interval is max(1,2,1,2,1)min(1,2,1,2,1)=21=1\max(1,2,1,2,1)-\min(1,2,1,2,1)=2-1=1, which is the smallest among all intervals.

Constraints

For the testdata worth 2020 points, N100N \le 100.

For the testdata worth 4040 points, N2000N \le 2000.

For 100%100\% of the testdata, 2N1052 \le N \le 10^5, Ai<109|A_i| \lt 10^9.

Notes

This problem’s score follows the original COCI settings, with a full score of 7070.

Translated from COCI2018-2019 CONTEST #3 T2 Pismo.

Translated by ChatGPT 5