i costs bases[i]. Then you may add toppings: topping j costs toppings[j] per serving, and you can take 0, 1 or 2 servings of each. Skipping toppings altogether is fine too.
You want the dessert's price to be as close to budget as possible, above or below. Return that closest achievable price. If two prices are equally close, return the lower one.bases=[5, 9], toppings=[2, 6], budget=15 → 15
The base at 9 plus one serving of the topping at 6 comes to exactly 15.
bases=[4], toppings=[3], budget=8 → 7
The possible prices are 4, 7 and 10. The closest to 8 is 7, off by 1.
bases=[6, 12], toppings=[7], budget=9 → 6
The prices are 6, 13, 20, 12, 19 and 26. Both 6 and 12 are 3 away from 9, so the cheaper one, 6, wins.
bases[i], toppings[j] ≤ 10⁴budget ≤ 10⁴bases=[5, 9], toppings=[2, 6], budget=15
15
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.