made greedy algorithm work with subset pairs

Turned out to be relatively simple. Not rigorously tested, but the
changes are minor so I suspect it's fine.