FPEvalDataset/LeetCodeProblem
0305
1{2 "id": 3107,3 "name": "maximum_spending_after_buying_items",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/maximum-spending-after-buying-items/",6 "date": "2023-10-28 00:00:00",7 "task_description": "You are given a **0-indexed** `m * n` integer matrix `values`, representing the values of `m * n` different items in `m` different shops. Each shop has `n` items where the `jth` item in the `ith` shop has a value of `values[i][j]`. Additionally, the items in the `ith` shop are sorted in non-increasing order of value. That is, `values[i][j] >= values[i][j + 1]` for all `0 <= j < n - 1`. On each day, you would like to buy a single item from one of the shops. Specifically, On the `dth` day you can: Pick any shop `i`. Buy the rightmost available item `j` for the price of `values[i][j] * d`. That is, find the greatest index `j` such that item `j` was never bought before, and buy it for the price of `values[i][j] * d`. **Note** that all items are pairwise different. For example, if you have bought item `0` from shop `1`, you can still buy item `0` from any other shop. Return _the **maximum amount of money that can be spent** on buying all _ `m * n` _products_. **Example 1:** ``` **Input:** values = [[8,5,2],[6,4,1],[9,7,3]] **Output:** 285 **Explanation:** On the first day, we buy product 2 from shop 1 for a price of values[1][2] * 1 = 1. On the second day, we buy product 2 from shop 0 for a price of values[0][2] * 2 = 4. On the third day, we buy product 2 from shop 2 for a price of values[2][2] * 3 = 9. On the fourth day, we buy product 1 from shop 1 for a price of values[1][1] * 4 = 16. On the fifth day, we buy product 1 from shop 0 for a price of values[0][1] * 5 = 25. On the sixth day, we buy product 0 from shop 1 for a price of values[1][0] * 6 = 36. On the seventh day, we buy product 1 from shop 2 for a price of values[2][1] * 7 = 49. On the eighth day, we buy product 0 from shop 0 for a price of values[0][0] * 8 = 64. On the ninth day, we buy product 0 from shop 2 for a price of values[2][0] * 9 = 81. Hence, our total spending is equal to 285. It can be shown that 285 is the maximum amount of money that can be spent buying all m * n products. ``` **Example 2:** ``` **Input:** values = [[10,8,6,4,2],[9,7,5,3,2]] **Output:** 386 **Explanation:** On the first day, we buy product 4 from shop 0 for a price of values[0][4] * 1 = 2. On the second day, we buy product 4 from shop 1 for a price of values[1][4] * 2 = 4. On the third day, we buy product 3 from shop 1 for a price of values[1][3] * 3 = 9. On the fourth day, we buy product 3 from shop 0 for a price of values[0][3] * 4 = 16. On the fifth day, we buy product 2 from shop 1 for a price of values[1][2] * 5 = 25. On the sixth day, we buy product 2 from shop 0 for a price of values[0][2] * 6 = 36. On the seventh day, we buy product 1 from shop 1 for a price of values[1][1] * 7 = 49. On the eighth day, we buy product 1 from shop 0 for a price of values[0][1] * 8 = 64 On the ninth day, we buy product 0 from shop 1 for a price of values[1][0] * 9 = 81. On the tenth day, we buy product 0 from shop 0 for a price of values[0][0] * 10 = 100. Hence, our total spending is equal to 386. It can be shown that 386 is the maximum amount of money that can be spent buying all m * n products. ``` **Constraints:** `1 <= m == values.length <= 10` `1 <= n == values[i].length <= 104` `1 <= values[i][j] <= 106` `values[i]` are sorted in non-increasing order.",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "values = [[8,5,2],[6,4,1],[9,7,3]]",12 "output": "285 "13 },14 {15 "label": "Example 2",16 "input": "values = [[10,8,6,4,2],[9,7,5,3,2]]",17 "output": "386 "18 }19 ],20 "private_test_cases": [21 {22 "input": [23 [],24 [],25 [],26 [],27 [],28 []29 ],30 "output": 22706294111557431 },32 {33 "input": [34 [],35 [],36 [],37 [],38 [],39 [],40 [],41 [],42 [],43 []44 ],45 "output": 29218015908285846 },47 {48 "input": [49 [],50 [],51 [],52 [],53 []54 ],55 "output": 47909859918109656 },57 {58 "input": [59 [],60 [],61 [],62 [],63 [],64 [],65 [],66 [],67 []68 ],69 "output": 78378224832570 },71 {72 "input": [73 [],74 [],75 [],76 [],77 [],78 [],79 [],80 []81 ],82 "output": 161918375697310783 }84 ],85 "haskell_template": "maxSpending :: [[Int]] -> Int\nmaxSpending values ",86 "ocaml_template": "let maxSpending (values: int list list) : int = ",87 "scala_template": "def maxSpending(values: List[List[Int]]): Int = { \n \n}",88 "java_template": "class Solution {\n public long maxSpending(int[][] values) {\n \n }\n}",89 "python_template": "class Solution(object):\n def maxSpending(self, values):\n \"\"\"\n :type values: List[List[int]]\n :rtype: int\n \"\"\"\n "90}