An efficient algorithm on time-fractional partial differential equations with variable coefficients