Woburn Challenge 2016-17 Round 4 - Junior Division
"I don't have to cower in a herd anymore. Instead, I can be an
astronaut!"
"I don't have to be a lonely hunter anymore. Today I can hunt for tax
exemptions; I'm gonna be an actuary!"
"And I can make the world a better place, I am going to be… a police
officer!"
In an ever more progressive and open-minded society, Zootopia's slogan "Anyone can be Anything" is becoming a reality at last. Its animal inhabitants are no longer strictly bound to traditional professions based on their species, and are instead free to pursue any careers that they please.
There are different categories of jobs in Zootopia, with jobs which have typically been performed by predators falling into category , and jobs traditionally associated with prey falling into category . There are also young animals who are preparing to join the workforce. Each animal will get assigned to one of the job categories. However, their assignment will no longer be dictated by their species - instead, the animal will apply for their preferred job category , and will have a fair shot of getting a spot in it, with the help of the city's strict anti-discrimination hiring laws.
Unfortunately, however, even the overcoming of deep-rooted social prejudices doesn't mean that everyone can end up happy. For example, even if everybody wants to become an astronaut, society can realistically only continue running smoothly if the majority of its members contribute in more practical roles, regardless of their wishes. To that end, the job category has openings, indicating that exactly new animals must be assigned to it. The total number of openings is equal to the number of animals , meaning that once every animal has been assigned to a job category, both categories' openings should be exactly filled.
Perhaps everyone can't be anything, but at least some animals can be allowed to live out their dreams. Once all animals have been assigned to job categories in some valid fashion, what's the maximum number of animals which can end up having been assigned to their preferred job category?
Input Specification
The first line of input consists of a single integer .
The second line consists of two space-separated integers and .
The third line consists of space-separated integers .
Output Specification
Output a single line consisting of a single integer - the maximum number of animals who can be assigned to their preferred job category.
Sample Input
5
3 2
2 1 1 2 2
Sample Output
4
Sample Explanation
One optimal arrangement is to assign the first and last animals to the
job category, and the remaining animals to the job category.
In this situation, all of the animals will be assigned to their
preferred job category besides the animal, who will get stuck with
job category instead of .
Comments