C++ | Simple Dynamic Programming Solution | Easy to Understand
\nclass Solution {\npublic:\n    int dp[50005][3];\n    int f(vector<int>& arr,int taken,int idx){\n        if(taken >= 2)  return 0;\n        if(idx >= arr.siz
```\nclass Solution {\npublic:\n    int dp[50005][3];\n    int f(vector<int>& arr,int taken,int idx){\n        if(taken >= 2)  return 0;\n        if(idx >= arr.size())   return -1e7;\n        else if(dp[idx][taken] != -1)   return dp[idx][taken];\n\n        int pick = arr[idx] + f(arr,taken+1,idx+1);\n        int notPick = f(arr,taken,idx+1);\n        \n        if(taken == 1){\n            pick = pick - idx;\n        }else{\n            pick += idx;\n        }\n                \n        return dp[idx][taken] = max(pick,notPick);\n    }\n    \n    int maxScoreSightseeingPair(vector<int>& values) {\n        memset(dp,-1,sizeof(dp));\n        return f(values,0,0);\n    }\n};\n\n/**\na[i] + b[j] + i - j\na[i] + i + b[j] - j;\n\n*/\n```\n\n\nTime Complexity = O(n * 3) \nSpace Complexity = O(n *  3)
['Dynamic Programming', 'Recursion', 'Memoization', 'C']