A Variational Criterion for Nonintegrability