You are viewing a single comment's thread. Return to all comments →
I tried DP but I'm getting "Abort Called" in last few test cases.
int twoStacks(int x, vector<int> a, vector<int> b) { int n=(int)a.size(); int m=(int)b.size(); int res=0; vector<vector<int>> D; D.resize(n+1); for (int i = 0; i < n+1; ++i) D[i].resize(m+1); D[0][0] = 0; for(int i=1; i<n+1; i++){ D[i][0] = D[i-1][0] + a[i-1]; if(D[i][0] <= x){ res = std::max(i+0,res); } } for(int j=1; j<m+1; j++){ D[0][j] = D[0][j-1] + b[j-1]; if(D[0][j] <= x){ res = std::max(0+j,res); } } for(int i=1; i<n+1; i++){ for(int j=1; j<m+1; j++){ D[i][j] = D[0][j] + D[i][0]; if(D[i][j] <= x){ res = std::max(i+j,res); } } } return res; }
Game of Two Stacks
You are viewing a single comment's thread. Return to all comments →
I tried DP but I'm getting "Abort Called" in last few test cases.