#A. Pupils Redistribution

    远端评测题 1000ms 256MiB

Pupils Redistribution

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Pupils Redistribution

题面翻译

题目描述

在Berland每一个高中生的成绩都很有特点 — 一个在1155 之间的整数。

在高中0xFF有两个学生小组,每个小组都有nn 名学生。每名学生的成绩就像所知的 — 一个在1155 之间的整数。

学校主任想要在小组间重新分配这些学生以达到在两个小组间成绩为11 的学生数量相等,成绩为22 的学生数量相等,以此类推。换句话说,学校主任的目的是,在改变完学生的组成后,每个成绩在两个小组都有相同的人数。

实现这个的方式是,有计划的在小组间进行一系列的学生交换。每次交换中主任都会从AA 班(原文就是班,实际应该是组的意思)中选一名学生,再从B班中选一名学生。然后,交换他们所属的组。

输出最少的交换数,来使得每个成绩在两个小组都有相同的人数。

输入格式:

第一行输入一个整数nn1n1001\leq n\leq 100 ) — 两个组各自的学生数。

第二行包含一列整数a1,a2,,ana_1,a_2,\dots,a_n1ai51\leq a_i\leq 5 ) — aia_i 为在AA 组第ii 名学生的成绩。

第三行包含一列整数b1,b2,,bnb_1,b_2,\dots,b_n1bi51\leq b_i\leq 5 ) — bib_i 为在BB 组第ii 名学生的成绩。

输出格式:

输出完成要求所需要的最少交换数,或-1,表示要求根本不能完成。

感谢@Khassar 提供的翻译

题目描述

In Berland each high school student is characterized by academic performance — integer value between 1 1 and 5 5 .

In high school 0xFF there are two groups of pupils: the group A A and the group B B . Each group consists of exactly n n students. An academic performance of each student is known — integer value between 1 1 and 5 5 .

The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1 1 , the same number of students whose academic performance is 2 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.

To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A A and one student of class B B . After that, they both change their groups.

Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.

输入格式

The first line of the input contains integer number n n ( 1<=n<=100 1<=n<=100 ) — number of students in both groups.

The second line contains sequence of integer numbers a1,a2,...,an a_{1},a_{2},...,a_{n} ( 1<=ai<=5 1<=a_{i}<=5 ), where ai a_{i} is academic performance of the i i -th student of the group A A .

The third line contains sequence of integer numbers b1,b2,...,bn b_{1},b_{2},...,b_{n} ( 1<=bi<=5 1<=b_{i}<=5 ), where bi b_{i} is academic performance of the i i -th student of the group B B .

输出格式

Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.

样例 #1

样例输入 #1

4
5 4 4 4
5 5 4 5

样例输出 #1

1

样例 #2

样例输入 #2

6
1 1 1 1 1 1
5 5 5 5 5 5

样例输出 #2

3

样例 #3

样例输入 #3

1
5
3

样例输出 #3

-1

样例 #4

样例输入 #4

9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1

样例输出 #4

4

12.24上午8点半练习及作业

未认领
状态
已结束
题目
7
开始时间
2023-12-24 0:00
截止时间
2024-1-18 23:59
可延期
24 小时