## Wesley's Anger Contest 6 Problem 2 - Cheap Christmas Lights

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Now that Christmas is over, Wesley needs to take down his Christmas lights! He has a line of lights, some of which may be on, and Wesley needs all the lights to be off before he can unplug them (or else he'll receive a deadly electrical shock). Each light has a corresponding switch that can be used to turn the light on or off, and Wesley can use at most one of these switches every second, starting from the second. However, these lights are finicky, and in the next seconds they will toggle their state on their own! Specifically, during the second the light will flip its state. Wesley wants to take the lights down as soon as possible, so he would like to know what's the earliest time possible for all the lights to be off, assuming he uses switches in an ideal manner. In particular, output the least such that all lights can be turned off by the end of the second by some sequence of switch usages. Note if all lights are initially off, then the least such is .

#### Constraints

For this problem, you will be required to pass all the samples in order to receive any points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

for all
for all

#### Input Specification

On the first line will be two integers and , the number of lights and the number of unsolicited changes the lights will make.

The second line will contain integers , the initial state of the lights. indicates that the light is initially on, otherwise off.

The third and final line will contain integers , which denotes that the light is toggled on/off during the second.

#### Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output a single integer, the earliest time (in seconds) it will take for Wesley to turn all the lights off. Note that if all the lights can be turned off before seconds have passed, Wesley will ignore any future toggles and take them down immediately.

#### Sample Input 1

3 3
1 1 1
1 2 3

#### Sample Output 1

2

#### Sample Input 2

5 8
0 1 0 1 1
1 2 2 1 4 3 2 1

#### Sample Output 2

4