[Python] Explained with diagram, Iterative DP solution,  (Beats 98% TC)
Worst Case time complexity = O(nk^2)\n\nIntuition* - Let\'s say we are standing at pile[i] and have already computed piles<i. And we have calculated the maximum
Worst Case time complexity = O(n*k^2)\n\n**Intuition** - Let\'s say we are standing at pile[i] and have already computed piles<i. And we have calculated the maximum possible sum of r (0<r<=k) number of coins uptill pile[i]. Now to calculate maximum possible sum using pile[i]  following steps can be followed:-\n1) maximum sum uptill pile[i] is stored in array max_arr for 0<coins<=k\n2) maintain an array cur_arr which stores coin sum including pile[i]. In pile[i], we have to calculate sum one by one using  0<top-coins<=k from pile[i]. cur_arr will hold the maximum value for a particular no. of coins less than using pile[i].\n3) After cur_arr is calculated using k coins of pile[i], max_arr is updated to include greater values from cur_arr.\n4) After all n piles are iterated, return max_arr[k].\n  ![image](https://assets.leetcode.com/users/images/219e4955-2835-4798-a905-b715042b5a07_1662145396.921648.jpeg)![image](https://assets.leetcode.com/users/images/44ad72f0-8d6e-4775-ba27-aec22309741d_1662145445.133529.jpeg)\n![image](https://assets.leetcode.com/users/images/fc346985-0b6e-4cb5-9d5c-27f6b126a5a4_1662146313.2433224.jpeg)\n\n\n\n\n```\nclass Solution:\n    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n        \n        n=len(piles)\n        topk=[]\n            \n        cur_arr=[0]*(k+1)\n        max_arr=[0]*(k+1)\n        \n        for x in piles:\n            i=0\n            cursum=0\n            while i<k and i<len(x):\n                cursum+=x[i]\n                j=0\n                while i+1+j<=k:\n                    if j>0 and max_arr[j]==0:\n                        break\n                    cur_arr[i+1+j]=max(cur_arr[i+1+j],max_arr[j]+cursum)\n                    j+=1\n                i+=1\n                \n            for t in range(i+j):\n                if cur_arr[t]>max_arr[t]:\n                    max_arr[t]=cur_arr[t]\n                    \n        return max_arr[k]\n            \n            \n                ```
['Dynamic Programming', 'Python']