> For the complete documentation index, see [llms.txt](https://cai-sen-se.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cai-sen-se.gitbook.io/leetcode/1001-2000/1014.-zui-jia-guan-guang-zu-he.md).

# 1014. 最佳观光组合

<https://leetcode-cn.com/problems/best-sightseeing-pair/>

## 解法一：

求`A[i]+A[j]+i-j`可以分解为`A[i]+i`和`A[j]-j`，由于i\<j，于是一次遍历，用pre\_max记录`A[i]+i`最大值

```python
class Solution:
    def maxScoreSightseeingPair(self, A: List[int]) -> int:
        res = 0
        pre_max = 0
        for j in range(len(A)):
            res = max(res, A[j] - j + pre_max)
            pre_max = max(pre_max, A[j]+j)
        return res
```
