You are given an array points containing the coordinates of points on a 2D plane, sorted by their x-values, where
points[i] = [xi, yi] and it is guaranteed that xi < xj for all 1 ≤ i < j ≤ points.length.
You are also given an integer k.
Your task is to return the maximum value of the equation:
subject to the constraint:
and .
It is guaranteed that at least one pair of points satisfies the constraint.
Input: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1
Output: 4
Explanation:
The first two points satisfy |1 − 2| ≤ 1 → equation = 3 + 0 + |1 − 2| = 4 The third and fourth points also satisfy |5 − 6| ≤ 1 → equation = 10 + (−10) + |5 − 6| = 1 No other pairs satisfy the condition. Hence, the maximum value is 4.
Input: points = [[0,0],[3,0],[9,2]], k = 3
Output: 3
Explanation:
Only the first two points satisfy |0 − 3| ≤ 3. Equation value = 0 + 0 + |0 − 3| = 3. Therefore, the output is 3.
Accepted:
Submission: