#K6596. Max Difference With Condition
Max Difference With Condition
Max Difference With Condition
You are given a sequence of integers representing weights. Your task is to find the maximum absolute difference between any two elements in the sequence, under the condition that there is at least one element placed between them. In other words, if we choose two indices \(i\) and \(j\) such that \(j \ge i+2\), compute the absolute difference \(|weights[j]-weights[i]|\), and determine the maximum value over all possible index pairs.
Note: Use zero-based indexing. It is guaranteed that the list contains at least three elements.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains an integer \(n\) which denotes the number of elements in the sequence. The second line contains \(n\) space-separated integers representing the weights.
outputFormat
Output the maximum absolute difference that satisfies the condition, printed to standard output (stdout).
## sample5
1 5 9 3 8
8