💥Runtime beats 100.00%, Memory beats 84.38% [EXPLAINED]
\n# Intuition\nYou have several piles of coins, and you need to select exactly k coins in total from these piles to maximize their combined value. Each pile all
\n# Intuition\nYou have several piles of coins, and you need to select exactly k coins in total from these piles to maximize their combined value. Each pile allows you to only pick coins from the top.\n\n\n# Approach\nDynamic Programming (DP) Array: Think of it like a big list where each position represents the maximum money you can get if you pick that many coins. We use this list to keep track of the best choices as we process each pile.\n\n\nPrefix Sums: For each pile, calculate the total value of picking the top 1, 2, 3, etc., coins. This helps us quickly find out how much money we get if we decide to take a certain number of coins from the pile.\n\n\nUpdate the DP Array: For each pile, update the DP list to include the new maximum values you can get by adding coins from the current pile.\n\n# Complexity\n- Time complexity:\nO(n * k): Where n is the number of piles, and k is the number of coins you want to pick. We go through each pile and update our list of possible maximum values.\n\n- Space complexity:\nO(k): Because we use a list to keep track of the maximum values for up to k coins.\n\n# Code\n```csharp []\npublic class Solution {\n    public int MaxValueOfCoins(IList<IList<int>> piles, int k) {\n        int[] dp = new int[k + 1];  // DP array to store the max value for picking x coins\n\n        foreach (var pile in piles) {\n            int pileSize = pile.Count;\n            int[] prefixSum = new int[pileSize + 1];  // Prefix sum to quickly calculate the sum of first x coins in the pile\n\n            // Calculate prefix sum for the current pile\n            for (int i = 0; i < pileSize; i++) {\n                prefixSum[i + 1] = prefixSum[i] + pile[i];\n            }\n\n            // Update DP array from back to front\n            for (int coins = k; coins > 0; coins--) {\n                // Try taking 0 to min(coins, pileSize) coins from the current pile\n                for (int taken = 1; taken <= Math.Min(coins, pileSize); taken++) {\n                    dp[coins] = Math.Max(dp[coins], dp[coins - taken] + prefixSum[taken]);\n                }\n            }\n        }\n\n        return dp[k];  // The answer is the maximum value we can get by taking exactly k coins\n    }\n}\n\n```
['C#']