The solution I went with is to walk the entire bank of batteries with their joltages and pair them up. At every step I can either form an incomplete candidate (Left x), or a complete candidate (Right (a, b)) if I already have a previous candidate.