#C1417. Maximum Product of Two Elements with Limited Difference

    ID: 43789 Type: Default 1000ms 256MiB

Maximum Product of Two Elements with Limited Difference

Maximum Product of Two Elements with Limited Difference

Given a sorted list of integers and a non-negative integer (k), your task is to determine the maximum product of any two distinct elements such that the absolute difference between them is at most (k). If there is no valid pair, output (-1).

Note: The input array is guaranteed to be sorted in non-decreasing order.

inputFormat

The input consists of two lines:
1. The first line contains two space-separated integers (n) and (k), where (n) is the number of elements and (k) is the maximum allowed difference.
2. The second line contains (n) space-separated integers representing the sorted array.

outputFormat

Output a single integer representing the maximum product of two distinct elements whose difference is no more than (k), or (-1) if no such pair exists.## sample

5 2
1 3 7 9 10
90