CF779A.Pupils Redistribution
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 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, the same number of students whose academic performance is 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 and one student of class 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.
在贝尔兰,每名高中生的学业成绩用一个介于 1 到 5 之间的整数表示。
在高中 0xFF 中有两组学生:A 组和 B 组,每组恰好包含 $ n $ 名学生。每名学生的学业成绩均已知,为一个介于 1 到 5 之间的整数。
校方主管希望重新分配学生,使得两个组中各学业成绩(即成绩为 1 的学生人数、成绩为 2 的学生人数……以此类推)的人数均相等。换言之,主管的目标是调整两组的构成,使得对每一种学业成绩值,两组中具有该成绩的学生人数完全相同。
为实现这一目标,计划执行若干次 A 组与 B 组之间的学生交换操作。每次交换操作中,主管从 A 组选出一名学生,同时从 B 组选出一名学生,然后两人互换所在小组。
请输出达成上述目标所需的最少交换次数。
输入格式
The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.
The second line contains sequence of integer numbers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 5), where a__i is academic performance of the i-th student of the group A.
The third line contains sequence of integer numbers _b_1, _b_2, ..., b__n (1 ≤ b__i ≤ 5), where b__i is academic performance of the i-th student of the group B.
输入的第一行包含一个整数 $ n ( 1 \leq n \leq 100 $)—— 表示两个小组中的学生人数。
第二行包含一个整数序列 $ a_1, a_2, \dots, a_n ( 1 \leq a_i \leq 5 $),其中 $ a_i $ 表示小组 $ A $ 中第 $ i $ 位学生的学业成绩。
第三行包含一个整数序列 $ b_1, b_2, \dots, b_n ( 1 \leq b_i \leq 5 $),其中 $ b_i $ 表示小组 $ B $ 中第 $ i $ 位学生的学业成绩。
输出格式
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
6 1 1 1 1 1 1 5 5 5 5 5 5
输出#2
3
输入#3
1 5 3
输出#3
-1
输入#4
9 3 2 5 5 2 3 3 3 2 4 1 4 1 1 2 4 4 1
输出#4
4
输入解题思路,AI测评打分。不知道怎么写?