C++ 6 Lines One Pass With Explanation.
Solution\n\nThe basic way is to use mathematics.\n\nAccording to the description: The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i 
**Solution**\n\nThe basic way is to use mathematics.\n\nAccording to the description: The score of a pair (`i < j`) of sightseeing spots is `values[i] + values[j] + i - j`, and our goal it to maximize the score.\n\nThen, we just modify this formula: `values[i] + values[j] + i - j` = `(values[j] - j) + (values[i] + i) `.\n\nSo, the only thing for us is to find an anwser: `(values[j] - j) + max(values[i] + i) `, where `i < j`.\n\n**Code**\n\n```cpp\nclass Solution {\npublic:\n    int maxScoreSightseeingPair(vector<int>& values) {\n        int n = values.size(), prev = values[0] + 0, ans = 0;\n        for(int i = 1; i < n; i++) {\n            ans = max(ans, prev + values[i] - i);\n            prev = max(prev, values[i] + i);\n        }\n        return ans;\n    }\n};\n```\n\n\n**Complexity**\n\nTime complexity: O(n)\n\nSpace complexity: O(1)\n\n
['C']