You are given an integer array values where values[i] is the score of the i-th sightseeing spot. Two spots i < j are a distance j - i apart. The score of the pair is values[i] + values[j] + i - j: the sum of their scores minus the distance between them. Return the maximum score over all pairs.
You are given an integer array values where values[i] is the score of the i-th sightseeing spot. Two spots i < j are a distance j - i apart. The score of the pair is values[i] + values[j] + i - j: the sum of their scores minus the distance between them. Return the maximum score over all pairs.
Example 1:
Input: {"values":[8,1,5,2,6]}
Output: 11
Constraints:
2≤values.length≤5×104
1≤values[i]≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"values":[8,1,5,2,6]}
Score of a pair = (values[i] + i) + (values[j] - j). Spot 0 is the first left end: it offers values[0] + 0 = 8.
spots along the road, bar height = value; the left end's value fades by 1 per step of distance