n stocks. Today stock i costs price_now[i], and in a year it will be worth price_later[i]. You have budget money. Each stock can be bought at most once, and the total cost of your purchases must not exceed the budget.
A year later you sell everything you bought. Return the largest profit, the proceeds minus what you spent. Buying nothing is allowed and gives a profit of 0.price_now=[4, 7, 3, 5], price_later=[6, 12, 3, 9], budget=12 → 9
Stock 2 earns nothing (3 → 3). The best is stocks 1 and 3, bought for 7 + 5 = 12 and sold for 12 + 9 = 21: a profit of 9.
price_now=[10, 8], price_later=[20, 15], budget=5 → 0
The budget cannot cover any stock, so the profit is 0.
price_now=[4, 7, 3, 5], price_later=[6, 12, 3, 9], budget=12
9
Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.