Solved LeetCode program · 373 of 1,000
#0502 · IPO
Original English source
Keep a shared profits holding 1, 2, and 3. Keep a shared capital holding 0, 1, and 1. Keep a shared used holding 0, 0, and 0. Keep a shared count of 3. Keep a shared wallet of 0. Keep a shared bestproject of 0. Keep a shared bestprofit of 0.
To choose. Set bestproject to -1. Set bestprofit to -1.
For every project from 0 to count minus 1.
The need is item project of capital. If item project of used is 0 and need is at most wallet and item project of profits is more than bestprofit, set bestproject to project, set bestprofit to item project of profits.
For every round from 1 to 2.
Choose. If bestproject is at least 0, set item bestproject of used to 1, add bestprofit to wallet.
Show wallet.
Expected stdout
4