Lifetime measurement of charm mesons produced in π-p and pp interactions at 360 GeV/c