#K57567. Maximum Difference After Sorting

    ID: 30449 Type: Default 1000ms 256MiB

Maximum Difference After Sorting

Maximum Difference After Sorting

You are given an array of n integers. Your task is to compute the maximum difference between consecutive elements after sorting the array in non-decreasing order.

More formally, let the sorted array be \(a_1, a_2, \dots, a_n\). You need to find the maximum value of \(a_i - a_{i-1}\) for \(2 \le i \le n\). If the array has fewer than two elements, the answer is 0.

Input and Output Details:

  • If the list is empty or contains a single element, output 0.
  • Otherwise, compute and output the maximum difference as defined.

In mathematical notation, the answer is given by:

[ \max_{2 \leq i \leq n}(a_i - a_{i-1}) ]

Note: The input is provided via standard input (stdin) and the output should be sent to standard output (stdout).

inputFormat

The first line contains a single integer n (\(0 \le n \le 10^5\)) which represents the number of elements in the array.

If n > 0, the second line contains n space-separated integers. Each integer fits in a 32-bit signed integer.

Input is provided through standard input (stdin).

outputFormat

Output a single integer representing the maximum difference between consecutive elements after sorting the array. The result should be printed to standard output (stdout).

## sample
4
3 6 9 1
3