The TransCompilator

Solved LeetCode program · 452 of 1,000

#0638 · Shopping Offers

Medium Array chunk-10.md

Original English source

Keep a shared prices holding 2 and 5. Keep a shared wants holding 3 and 2. Keep a shared bundles holding 3, 0, 5, 1, 2, and 10. Keep a shared width of 3. Keep a shared deals of 2. Keep a shared best of 1000000. Keep a shared kinds of 2. Keep a shared costspot of width minus 1. Keep a shared fits of 0. Keep a shared regular of 0.
To measure from bundle (a whole number) with spot (a whole number). If spot is at least kinds, return. The amount is item (bundle times width plus spot) of bundles. If amount is more than item spot of wants, set fits to 0. Measure from bundle with spot plus 1.

To charge with spot (a whole number). If spot is at least kinds, return. The amount is item spot of wants times item spot of prices. Add amount to regular. Charge with spot plus 1.

To take from bundle (a whole number) with spot (a whole number). If spot is at least kinds, return. The amount is item (bundle times width plus spot) of bundles. Decrease item spot of wants by amount. Take from bundle with spot plus 1.

To carry from bundle (a whole number) with spot (a whole number). If spot is at least kinds, return. The amount is item (bundle times width plus spot) of bundles. Increase item spot of wants by amount. Carry from bundle with spot plus 1.

To settle with spent (a whole number). Set regular to 0. Charge with 0. The total is spent plus regular. If total is less than best, set best to total.

To explore from bundle (a whole number) with spent (a whole number). If spent is at least best, return. If bundle is at least deals, settle with spent, return. Explore from bundle plus 1 with spent. Set fits to 1. Measure from bundle with 0.
If fits is 1.
Take from bundle with 0. Explore from bundle with spent plus item (bundle times width plus costspot) of bundles. Carry from bundle with 0.

Explore from 0 with 0. Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

14