#K11266. Maximum Elevation Difference

    ID: 23431 Type: Default 1000ms 256MiB

Maximum Elevation Difference

Maximum Elevation Difference

You are given an array of elevations. Considering only the first \(k\) elements of the array, your task is to choose two distinct points such that the two indices are at most \(m\) positions apart. Compute and output the maximum absolute difference between the elevations at these two points.

Formally, let \(elevations[0..k-1]\) be the first \(k\) elements of the array. Find \[ \max_{0 \leq i < j \leq k-1,\; j-i \leq m} |elevations[j] - elevations[i]| \]

The absolute difference between two numbers \(a\) and \(b\) is defined as \(|a-b|\).

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  1. The first line contains three integers \(n\), \(k\), and \(m\), where \(n\) is the number of elements in the elevation array, \(k\) is the number of elements (starting from index 0) to consider, and \(m\) is the maximum allowed difference in indices between the two points.
  2. The second line contains \(n\) space-separated integers representing the elevations at each point.

outputFormat

Output a single integer to standard output (stdout) representing the maximum elevation difference found under the given constraints.

## sample
6 4 2
1 5 2 8 4 3
6