✔ C++ Solution | DP | O(m * k) Time | O(k) Space
Time Complexity : O(m * k)\nSpace Complexity : O(k)\n\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        vector<i
`Time Complexity` : `O(m * k)`\n`Space Complexity` : `O(k)`\n```\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        vector<int> dp(k + 1, 0);\n        for(auto& pile: piles) {\n            for(size_t i = k; i >= 1; i--) {\n                int csum = 0;\n                for(int j = 0; j < min(i, pile.size()); j++) {\n                    csum += pile[j];\n                    dp[i] = max(dp[i], dp[i - j - 1] + csum);\n                }\n            }\n        }\n        return dp[k];\n    }\n};\n```
['Dynamic Programming', 'C']