Just as much 'work' is done if the two bars are touching against each other, supporting each other. Magnetism just allows action at a distance, which seems freaky - but is completely natural. After all, if the two bars support each other by touvhing, they're not actually touching - their respective molecules are repelling each other electrostatically. If you zoomed right in, you see that the atoms are actually 'floating' relative miles away from each other - and there's no energy being used up to make them do so either.