It's a slight variant on subset sum, which is NP-complete. Brute force is necessary if we want the exact result.