With respect to compliance with the agreement made under subsection (a) of this section, a State may expend a grant under section
300x–21 of this title to provide inpatient hospital services as treatment for substance abuse only if it has been determined, in accordance with guidelines issued by the Secretary, that such treatment is a medical necessity for the individual involved, and that the individual cannot be effectively treated in a community-based, nonhospital, residential program of treatment.