A team of eight swimmers wants two enter two 4x100meter medley relays in a swim meet. (The medley relay consists of one leg butterfly, one leg backstroke, one leg breaststroke, one leg freestyle.) Each swimmer can do all four strokes.
Keeping in mind that one swimmer can do only one leg, and that all four legs of both relays must be filled, devise an algorithm to allocate the swimmers so that the two relays have the lowest possible cumulative time.