### Fair Elections Codechef January long challenge 2021 solution || Fair Elections Codechef January 2021 Editorial

## Fair Elections Codechef January long challenge 2021 solution || Fair Elections Codechef January 2021 Editorial -

### Problem Statement-

Elections are coming soon. This year, two candidates passed to the final stage. One candidate is John Jackson and his opponent is Jack Johnson.

During the elections, everyone can vote for their favourite candidate, but no one can vote for both candidates. Then, packs of votes which went to the same candidate are formed. You know that for John Jackson, there are packs containing votes, and for Jack Johnson, there are packs containing votes.

The winner is the candidate that has strictly more votes than the other candidate; if both have the same number of votes, there is no winner. You are a friend of John Jackson and you want to help him win. To do that, you may perform the following operation any number of times (including zero): choose two packs of votes that currently belong to different candidates and swap them, i.e. change the votes in each of these packs so that they would go to the other candidate.

You are very careful, so you want to perform as few swaps as possible. Find the smallest number of operations you need to perform or determine that it is impossible to make John Jackson win.

### Input

- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers .
- The third line contains space-separated integers .

### Output

For each test case, print a single line containing one integer ― the smallest number of swaps needed to make John Jackson win, or if it is impossible.

### Constraints

- for each valid
- for each valid
- the sum of over all test cases does not exceed
- the sum of over all test cases does not exceed

### Subtasks

Subtask #1 (20 points):

Subtask #2 (80 points): original constraints

### Example Input

```
2
2 3
2 2
5 5 5
4 3
1 3 2 4
6 7 8
```

### Example Output

```
2
1
```

### Explanation

Example case 1: We can perform two swaps ― each time, we swap a pack of votes from and a pack of votes from . After that, John Jackson gets votes and Jack Johnson gets votes.

Example case 2: We can swap the pack of vote from and the pack of votes from . After that, John Jackson gets votes and Jack Johnson gets votes.

## Comments

## Post a Comment