plots land plots in a row along a road, numbered 0 to plots - 1. Buyers have sent bids bids: the bid [s, e, price] means a buyer wants all plots from s to e inclusive, as one deal, and will pay price for them.
You decide which bids to accept. A plot cannot be sold to two buyers, and a bid can only be accepted as a whole. Some plots may stay unsold.
Return the most money you can make.plots=6, bids=[[0, 1, 5], [1, 3, 7], [2, 5, 6], [4, 5, 3]] → 11
Accept [0, 1] for 5 and [2, 5] for 6: they do not overlap, 11 in total. The priciest bid, [1, 3] for 7, only combines with [4, 5] for 3, which gives 10.
plots=3, bids=[[0, 2, 4], [0, 0, 2], [1, 1, 2], [2, 2, 1]] → 5
The three small bids together bring 2 + 2 + 1 = 5, more than 4 for the whole row.
plots=6, bids=[[0, 1, 5], [1, 3, 7], [2, 5, 6], [4, 5, 3]]
11
Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.