C++ | Explained | Dynamic Programming
Approch\nHere we are given that we have to maximize V[i] + V[j] + i - j, given i<j. In such question understanding this type of condition is very important, her
# Approch\nHere we are given that we have to maximize ```V[i] + V[j] + i - j```, given ```i<j```. In such question *understanding this type of condition is very important*, here we can see that i must be less than j so, for any  j ```V[ j ] - j``` is a fixed value and to maximize the given condition we must maximize ```V[i] + i``` where ```i<j``` so we keep track of this maximum value upto any j  and then find the maximum of ```( V[i] + i ) + (V[ j ] - j )``` in the complete array.\n\n```\nclass Solution {\npublic:\n    int maxScoreSightseeingPair(vector<int>& values) {\n        return solve(values);\n    }\n    int solve(vector<int>& nums){\n        int n = nums.size();\n\n        int vi_max = nums[0];\n        int ans = INT_MIN;\n        for(int i=1;i<n;i++){\n            ans = max(ans, vi_max + nums[i]-i);\n            vi_max = max(vi_max, nums[i]+i);\n        }\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C']