[Solution] Make A Equal to B solution codeforces

Make A Equal to B solution codeforces – You are given two arrays 𝑎a and 𝑏b of 𝑛n elements, each element is either 00 or 11.

Table of Contents

[Solution] Make A Equal to B solution codeforces

You can make operations of 22 kinds.

  • Pick an index 𝑖i and change 𝑎𝑖ai to 1𝑎𝑖1−ai.
  • Rearrange the array 𝑎a however you want.

Find the minimum number of operations required to make 𝑎a equal to 𝑏b.

Input

Each test contains multiple test cases. The first line contains a single integer 𝑡t (1𝑡4001≤t≤400) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer 𝑛n (1𝑛1001≤n≤100) — the length of the arrays 𝑎a and 𝑏b.

The second line of each test case contains 𝑛n space-separated integers 𝑎1,𝑎2,,𝑎𝑛a1,a2,…,an (𝑎𝑖ai is 00 or 11), representing the array 𝑎a.

The third line of each test case contains 𝑛n space-separated integers 𝑏1,𝑏2,,𝑏𝑛b1,b2,…,bn (𝑏𝑖bi is 00 or 11), representing the array 𝑏b.

[Solution] Make A Equal to B solution codeforces

For each test case, print the minimum number of operations required to make 𝑎a equal to 𝑏b.

Example
input

Copy
5
3
1 0 1
0 0 1
4
1 1 0 0
0 1 1 1
2
1 1
1 1
4
1 0 0 1
0 1 1 0
1
0
1

[Solution] Make A Equal to B solution codeforces

Copy
1
2
0
1
1
Note

In the first case, we need only one operation: change 𝑎1a1 to 1𝑎𝑖1−ai. Now 𝑎=[0,0,1]a=[0,0,1] which is equal to 𝑏b.

In the second case, the optimal way is to rearrange 𝑎a to get the array [0,1,1][0,1,1].

For Solution

“Click Here”

Leave a Comment