Rational social distancing policy during epidemics with limited healthcare capacity