2930. Number of Strings Which Can Be Rearranged to Contain Substring
You are given a 0-indexed
m * n
integer matrixvalues
, representing the values ofm * n
different items inm
different shops. Each shop hasn
items where thejth
item in theith
shop has a value ofvalues[i][j]
. Additionally, the items in theith
shop 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
dth
day you can:
- Pick any shop
i
.- Buy the rightmost available item
j
for the price ofvalues[i][j] * d
. That is, find the greatest indexj
such that itemj
was 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
0
from shop1
, you can still buy item0
from any other shop.Return the maximum amount of money that can be spent on buying all
m * n
products.
1 |
|