Lefties vs. Righties
InterviewTime limit1sMemory limit1024 MB
Given T topics and N experts labeled rightie or leftie, pick at least one expert per topic with equal numbers of each label, minimizing the total interviewed.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
Election season has begun. The news network you work for wants to present expert opinions on a variety of important topics. To give the appearance of being unbiased, the news chief insists that the experts interviewed cover a broad range of the political spectrum.
The political spectrum is so varied that this is hard to do. You decide to use a tried and true practice instead: each person is labeled either a rightie or a leftie. You want the job done as quickly as possible, so you want to conduct the fewest interviews possible.
More specifically, there are topics to be covered and experts. Each expert is experienced with exactly one of the topics you should cover, and each expert is either a rightie or a leftie. Interview the fewest experts possible such that the following conditions hold.
- For each topic, you interview at least one expert in that topic.
- You interview each expert at most once, since the audience would get bored otherwise.
- The number of rightie experts you interview is the same as the number of leftie experts you interview.
Input
The first line contains two integers () and (), the number of topics and the number of experts.
The next lines each contain an integer () and a character (). Here is the topic of the -th expert, and indicates whether that expert is a rightie (R) or a leftie (L).
Output
Output a single integer on a line by itself, the fewest interviews that can be conducted to satisfy these constraints. If it is not possible to satisfy all constraints, output .