#K60187. Longest Contiguous Subarray

    ID: 31031 Type: Default 1000ms 256MiB

Longest Contiguous Subarray

Longest Contiguous Subarray

You are given an array of integers A of length N and an integer X. Your task is to determine the length of the longest contiguous subarray such that the difference between the maximum and minimum elements in that subarray is at most X. In other words, find the largest L such that there is a segment of A with length L where:

\(\max(subarray) - \min(subarray) \leq X\)

The input will be provided via standard input and the result should be printed to standard output.

inputFormat

The input consists of two lines:

  • The first line contains two space-separated integers N and X, where N is the number of elements in the array and X is the maximum allowed difference.
  • The second line contains N space-separated integers representing the array A.

outputFormat

Output a single integer representing the length of the longest contiguous subarray that satisfies the condition.

## sample
6 3
10 1 2 3 10 4
3