Maturation of the humoral immune response as an optimization problem