Suppose you are given a file with the following information:
3W 4M 5
M2 W1
M3 W1
W2 M4
M1 W1
M4 W3
The top line specifies the number of candidates in each of two categories (Willons and Millons) and the total number of voters, respectively. Thus, there are 3 Willons running, 4 Millons running, and there are 5 voters.
The lines that follow specify a voters' vote FOR exactly one Willon or Millon and AGAINST exactly one Willon or Millon (each voter must vote FOR/AGAINST exactly one candidate of each category, and the first vote will always be FOR a candidate and the second will always be AGAINST a candidate). The task is to find the maximum number of voters who can have both their first and second votes satisfied. So, to clarify, the second line says that the first voter voted for Millon #2 and against Willon #1, the third line says the second voter voted for Millon #3 and against Willon #1, etc. So it's clear that not all 5 of these voters can have both of their votes satisfied because, for example, voter 3 votes against M4 and voter 5 votes for M4.
I've tried a number of things but I can't seem to discover how the problem is well-defined. For example, if I just count the number for a candidate and against a candidate and say that if one number exceeds the other then we have to discount the difference, I miss several cases. It seems like I can get very close to passing the variety of test cases produced from my test-case algorithm, but I always miss some by 2 or 3 votes. Which approach seems most appropriate here? Is there a way to do the problem sequentially through the voters?