DP isn't scary dude
\nclass Solution {\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n     /*\n     -> Pick the first coin from the pile and move to next.\n  
```\nclass Solution {\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n     /*\n     -> Pick the first coin from the pile and move to next.\n     -> Don\'t pick the first coin from pile and move to next.\n     -> Pick first coin and stay on the same pile to pick the next coin.\n     */   \n        int[][] dp = new int[piles.size()][k + 1];\n        for(var i:dp) Arrays.fill(i,-1);\n        return move(piles,k,0,dp);\n    }\n    private int move(List<List<Integer>> piles, int k, int pileInd,int[][] dp) {\n        if(k == 0) return 0;\n        if(pileInd == piles.size())\n            return 0;\n        if(dp[pileInd][k] != -1) return dp[pileInd][k];\n        int dontPick = move(piles,k,pileInd + 1,dp);\n        int s = 0;\n        for(int i = 0; i < k && i < piles.get(pileInd).size(); i++) {\n            s += piles.get(pileInd).get(i);\n            dontPick = Math.max(dontPick,s + move(piles,k - (i + 1), pileInd + 1,dp));\n        }\n        // int dontPick = move(piles,k,pileInd + 1,sum,dp);\n        return dp[pileInd][k] = dontPick;\n    }\n}\n```
[]