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