In that case, you'll actually want the space remaining, which is totalspace-(a+b+c), where a, b, and c are your resources.
When adding resources, you'll add the full amount of new resources, or the total remaining space, whichever is lesser.
So a+min(newa,totalspace-(a+b+c))