2930. Number of Strings Which Can Be Rearranged to Contain Substring
You are given a 0-indexed
m * ninteger matrixvalues, representing the values ofm * ndifferent items inmdifferent shops. Each shop hasnitems where thejthitem in theithshop has a value ofvalues[i][j]. Additionally, the items in theithshop are sorted in non-increasing order of value. That is,values[i][j] >= values[i][j + 1]for all0 <= j < n - 1.On each day, you would like to buy a single item from one of the shops. Specifically, On the
dthday you can:
- Pick any shop
i.- Buy the rightmost available item
jfor the price ofvalues[i][j] * d. That is, find the greatest indexjsuch that itemjwas never bought before, and buy it for the price ofvalues[i][j] * d.Note that all items are pairwise different. For example, if you have bought item
0from shop1, you can still buy item0from any other shop.Return the maximum amount of money that can be spent on buying all
m * nproducts.
1 |
|