It is possible I've not fully understood the problem here (a common occurrence!), but, if there are just 5 components to 'a', each of which can be either 0 or 1, then there are only 32 possible combinations for 'a'. These are easily searched to find the one that minimises 'waste' (while keeping it non-negative). - see attached.
Alan