There are elderly men and elderly women at a party. Initially, nobody has danced.
In each turn, choose one man and one woman to dance together. This is allowed only if, before the turn begins, the man has danced at least as many times as the woman. Their numbers of dances then both increase by one.
You are given two arrays and . Man wants to dance at least times, and woman wants to dance at least times. The same pair may dance together multiple times, and anyone may dance more times than required.
Find the minimum number of turns needed to satisfy every person.
The only pair dances five times. Before each turn, both people have danced equally many times.
The first man and the first woman dance twice. Then the second man and the second woman dance once. All requirements are met in three turns.
Let the first pair dance three times and the second pair dance twice. Every turn is legal, and all requirements are met.
Write each turn as (man, woman). One optimal schedule is (2, 1), (3, 2), (1, 3), (1, 1), (1, 1), (1, 2), (1, 2). Every turn is legal, and the final counts are exactly the requested counts.
An optimal schedule is to let the first pair dance six times, the second pair dance six times, and the third pair dance four times. Every turn is legal. Some people dance more often than requested.