#K66532. Largest Absolute Difference of a Subarray

    ID: 32441 Type: Default 1000ms 256MiB

Largest Absolute Difference of a Subarray

Largest Absolute Difference of a Subarray

You are given an array of positive integers. Your task is to compute the largest absolute difference between the maximum and minimum elements among all contiguous subarrays. It can be proven that this maximum difference is achieved by taking the difference between the maximum and minimum elements of the entire array.

Formally, let \( A = [a_1, a_2, \dots, a_N] \) be the array. The answer is given as:

$$ \text{answer} = \max(A) - \min(A) $$

Read the input from standard input and write the result to standard output.

inputFormat

The input consists of two lines. The first line contains a single integer \(N\) — the number of elements in the array. The second line contains \(N\) space-separated positive integers representing the array \(A\).

outputFormat

Output a single integer — the largest absolute difference between the maximum and minimum elements among all contiguous subarrays of the given array.

## sample
5
1 3 6 4 5
5