Beats 100% || O(1) space || C++ || Greedy
IntuitionAt each index we have two choices, either take the maximum element encountered previously or take the previous element, whichever is bigger adjusted wi
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
At each index we have two choices, either take the maximum element encountered previously or take the previous element, whichever is bigger adjusted with increasing distance that increases by 1 in both cases.

# Approach
<!-- Describe your approach to solving the problem. -->
Take a variable maxi, to keep track of maximum element encountered so far and then compare it with just previous element, whichever is bigger, store it in maxi.
update ans if current value + maxi is bigger than the answer

# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxScoreSightseeingPair(vector<int>& values) {
        int maxi = values[0], ans = 0;
        for(int i=1; i<values.size(); i++){
            maxi = max(maxi-1, values[i-1]-1);
            ans = max(ans, values[i] + maxi);
        }
        return ans;
    }
};

auto speedup = [](){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0;}();
```
['Array', 'C++']