A variational problem with nonlocal constraints