Solve the general two bucket problem