Weighted Miranda-Talenti inequality and applications to linear elliptic equations with discontinuous coefficients