height and width width. Buyers want pieces of certain sizes: offers[i] = [h, w, p] means a piece of height h and width w sells for p. Any number of pieces of the same size can be sold, and you do not have to sell every size.
Every cut goes straight through the whole piece, horizontally or vertically, splitting it into two smaller rectangles. You may make as many cuts as you like. Because of the grain, pieces cannot be rotated: an h × w piece and a w × h piece are different.
Return the most money you can make from the height × width board.height=2, width=3, offers=[[1, 1, 1], [2, 3, 10], [1, 3, 6]] → 12
The whole board sells for 10. It is better to cut it lengthwise into two 1 × 3 strips and sell each for 6, for 12 in total.
height=3, width=1, offers=[[2, 1, 5]] → 5
Cut off a 2 × 1 piece and sell it for 5. Nobody buys the leftover 1 × 1 piece.
(h, w) in offers are distinctheight=2, width=3, offers=[[1, 1, 1], [2, 3, 10], [1, 3, 6]]
12
Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.