Statistical equilibrium of lithium in cool stars of different metallicity