Java Solution
\n# Code\n\nclass Solution {\n\tpublic static int maxValueOfCoins(List<List<Integer>> piles, int k) {\n\t\tint[] mv = new int[k + 1];\n\t\tint[] pileSum = new i
\n# Code\n```\nclass Solution {\n\tpublic static int maxValueOfCoins(List<List<Integer>> piles, int k) {\n\t\tint[] mv = new int[k + 1];\n\t\tint[] pileSum = new int[k + 1];\n\t\tfor (List<Integer> pile : piles) {\n\t\t\tint n = Math.min(k, pile.size());\n\t\t\tint sum = 0;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tpileSum[i] = sum += pile.get(i - 1);\n\t\t\tfor (int i = k; i > 0; i--) {\n\t\t\t\tint max = 0;\n\t\t\t\tfor (int j = Math.min(i, n); j >= 0; j--)\n\t\t\t\t\tmax = Math.max(max, pileSum[j] + mv[i - j]);\n\t\t\t\tmv[i] = max;\n\t\t\t}\n\t\t}\n\t\treturn mv[k];\n\t}\n}\n```
['Java']