funds and has a list of n projects. Project i can be started only if the current capital is at least entry[i]; once finished, it brings a net profit of gains[i], which is added to the capital. The threshold entry[i] itself is not spent.
Before the season ends, the studio can complete at most slots distinct projects, one at a time. Each project can be taken at most once.
Choose the projects and their order to make the final capital as large as possible, and return that capital.slots=2, funds=1, gains=[5, 2, 9], entry=[3, 1, 6] → 8
With 1 in hand only project 1 is open: capital becomes 3. Now project 0 (+5) is open, giving 8. Project 2 with its gain of 9 never becomes reachable within two slots.
slots=3, funds=0, gains=[4, 1, 2], entry=[5, 0, 1] → 3
0 → project 1 → 1 → project 2 → 3. Project 0 needs 5, which is out of reach, so the third slot goes unused. The answer is 3.
slots=2, funds=1, gains=[5, 2, 9], entry=[3, 1, 6]
8
Run checks the first 3 tests in your browser. Submit checks all 131 tests on the server, hidden ones included.