Tap here to switch tabs
Problem
Submissions

Problem: Maximum Spending After Buying Items

med
30 min
Try to solve the Maximum Spending After Buying Items problem.

Statement

You are given an mimesnm imes n integer matrix values representing the values of items in mm different shops, where each shop offers nn items. Each row values[i] is sorted in non increasing order.

Starting on day d=1d = 1 and continuing until day d=mimesnd = m imes n, you purchase exactly one item per day. On day dd, you can choose any shop with remaining items and purchase the last remaining item in that shop. The cost of purchasing an item of value vv on day dd is vimesdv imes d.

Return the maximum total spending possible to buy all mimesnm imes n items.

Constraints:

  • 1≤m==1 \leq m == values.length ≤10\leq 10

  • 1≤n==1 \leq n == values[i].length ≤104\leq 10^4

  • 1≤1 \leq values[i][j] ≤106\leq 10^6

  • values[i] is sorted in non increasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Spending After Buying Items

med
30 min
Try to solve the Maximum Spending After Buying Items problem.

Statement

You are given an mimesnm imes n integer matrix values representing the values of items in mm different shops, where each shop offers nn items. Each row values[i] is sorted in non increasing order.

Starting on day d=1d = 1 and continuing until day d=mimesnd = m imes n, you purchase exactly one item per day. On day dd, you can choose any shop with remaining items and purchase the last remaining item in that shop. The cost of purchasing an item of value vv on day dd is vimesdv imes d.

Return the maximum total spending possible to buy all mimesnm imes n items.

Constraints:

  • 1≤m==1 \leq m == values.length ≤10\leq 10

  • 1≤n==1 \leq n == values[i].length ≤104\leq 10^4

  • 1≤1 \leq values[i][j] ≤106\leq 10^6

  • values[i] is sorted in non increasing order.