Necessary and sufficient conditions for distances on the real line