Java || Runtime 53 ms Beats 95.6% Memory 43.1 MB Beats 82.72%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n        int n=piles.size();\n        int[] dp=new int[k+1];// k steps dynamic programming;\n        for(List<Integer> pile:piles){\n            int m=pile.size();\n            int[] cum=new int[m+1];\n            for(int i=0;i<m;i++) cum[i+1]=cum[i]+pile.get(i);\n            int[] curdp=new int[k+1];\n            for(int i=0;i<=k;i++){\n                for(int j=0;j<=m&& i+j <=k;j++){\n                    curdp[i+j]=Math.max(curdp[i+j],dp[i]+cum[j]);\n                }\n            }\n            dp=curdp;\n        }\n        return dp[k];\n    }\n}\n```
['Java']