As Kish said, D&D really has no mechanics in place to figure out experience for non-player characters.
However, ignoring that, D&D most certainly does not penalize characters for being farther away. Being an archer doesn't result in an XP penalty or anything like that. Everyone actively engaged in a battle, regardless of their actual actions, will get experience if the battle is won.