It seems that this is a slightly modification of subset sum, but I only come up with a naive approach, Anyone has a more effcient approach?