#C14504. Max-Min Difference

    ID: 44161 Type: Default 1000ms 256MiB

Max-Min Difference

Max-Min Difference

Given a list of integers, your task is to compute the difference between the maximum and minimum values in the list. Formally, if the list is \(A = [a_1, a_2, \dots, a_n]\), you need to compute:

[ d = \max(A) - \min(A) ]

If the list is empty (i.e. \(n = 0\)), output an error message instead.

This problem tests your ability to handle basic array operations and edge cases.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains a single integer \(n\) which represents the number of elements in the list.
  • If \(n > 0\), the second line contains \(n\) space-separated integers representing the list.

If \(n = 0\), there will be no second line.

outputFormat

Output a single line to stdout:

  • If \(n > 0\), output the difference between the maximum and minimum values in the list.
  • If \(n = 0\), output the exact string ERROR.
## sample
5
1 2 3 4 5
4