Optimization of functionals subject to integral constraints