Optimal resource allocation for containing epidemics on time-varying networks