Flexible polyandry in female flies is an adaptive response to infertile males