C++ | O(n2) | DP solution
dp[i][j].first = maximum difference we can get for the sub-array of [i, j], it is Alice\'s turn.\n\ndp[i][j].second = min difference we can get for the sub-arra
dp[i][j].first = maximum difference we can get for the sub-array of [i, j], it is Alice\'s turn.\n\ndp[i][j].second = min difference we can get for the sub-array of [i, j], it is Bob\'s turn.\n\nhence, \ndp[i][j].first = max(dp[i+1][j].second + (sum of the elements[i+1 to j]), dp[i][j-1] + (sum of the elements[i to j-1]))\ndp[i][j].second = min(dp[i+1][j].first - (sum of the elements[i+1 to j]), dp[i][j-1] + (sum of the elements[i to j-1]))\n\n\'+\' for maximizing difference - i.e. adding score to Alice\n\'-\' for minimizing difference - i.e. adding score to Bob\n\n**** In terms of fast execution\n3D vector < 2D vector of pair of ints < 2D array of pair of ints. in increasing order of speed of execution.\nArrays are faster than vectors.\n\n\n```\nclass Solution {\n\npublic:\n    int stoneGameVII(vector<int>& stones) {\n        int n = stones.size();\n        pair<int,int> dp[n][n];\n        int pfs[n];\n        for(int i=0;i<n;i++)\n            pfs[i] = stones[i] + ((i>0)?pfs[i-1]:0);\n        \n        for(int l=2;l<=n;l++){\n            for(int i=0;i<n-l+1;i++){\n                int j = i+l-1;\n                if(l == 2){\n                    int pos = max(stones[i], stones[j]);\n                    dp[i][j].first = pos;\n                    dp[i][j].second = -1*pos;\n                }else{\n                    int a_ = pfs[j]-pfs[i];\n                    int b_ = pfs[j-1]-((i==0)?0:pfs[i-1]);\n                    dp[i][j].first = max(dp[i+1][j].second + a_, \n                                     dp[i][j-1].second + b_);\n                    dp[i][j].second = min(dp[i+1][j].first - a_, \n                                     dp[i][j-1].first - b_);\n                }\n            }\n        }\n        return dp[0][n-1].first;\n    }\n};\n```
[]