A sufficient and necessary condition for nonconvex constrained optimization