@diddit I think the algorithm is pretty self-proved :)
The idea is each time we find a project with max profit and within current capital capability.
Since each time we gain max profit, the final result must be max.
I am not aware of other problem in leetcode looks like this. Greedy is indeed tricky.