We only need to maintain maximum maxtill (maxtill + values[i]-i) short & clean code in C++||Runs 0ms
ApproachComplexity
Time complexity: O(N)

Space complexity: O(1)
Code
![image.png](https://assets.leetcode.com/users/images/ebf496dc-d1f4-48cd-ac65-69bbd44667d1_1735261171.5992808.png)


# Approach
<!-- Describe your approach to solving the problem. -->

# 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 []
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize ("O3", "unroll-loops", "Ofast", "-ffloat-store")
static const auto harsh = []() { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    return 'c';
}();

class Solution {
public:
    int maxScoreSightseeingPair(vector<int>& values) {
        int ans = 0;
        int maxi = values[0];

        for(int i = 1; i<values.size(); i++){
            ans = max(ans, (maxi + values[i]-i));
            maxi = max(maxi, values[i]+i);
        }

        return ans;        
    }
};
```
![image.png](https://assets.leetcode.com/users/images/8f45f11e-c625-4599-9b28-e830bc2c66d0_1724569032.8579876.png)
['Array', 'Greedy', 'C++']