Pupils Redistribution
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Pupils Redistribution
题面翻译
题目描述
在Berland每一个高中生的成绩都很有特点 — 一个在 和 之间的整数。
在高中0xFF有两个学生小组,每个小组都有 名学生。每名学生的成绩就像所知的 — 一个在 和 之间的整数。
学校主任想要在小组间重新分配这些学生以达到在两个小组间成绩为 的学生数量相等,成绩为 的学生数量相等,以此类推。换句话说,学校主任的目的是,在改变完学生的组成后,每个成绩在两个小组都有相同的人数。
实现这个的方式是,有计划的在小组间进行一系列的学生交换。每次交换中主任都会从 班(原文就是班,实际应该是组的意思)中选一名学生,再从B班中选一名学生。然后,交换他们所属的组。
输出最少的交换数,来使得每个成绩在两个小组都有相同的人数。
输入格式:
第一行输入一个整数 ( ) — 两个组各自的学生数。
第二行包含一列整数 ( ) — 为在 组第 名学生的成绩。
第三行包含一列整数 ( ) — 为在 组第 名学生的成绩。
输出格式:
输出完成要求所需要的最少交换数,或-1,表示要求根本不能完成。
感谢@Khassar 提供的翻译
题目描述
In Berland each high school student is characterized by academic performance — integer value between and .
In high school 0xFF there are two groups of pupils: the group and the group . Each group consists of exactly students. An academic performance of each student is known — integer value between and .
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 , the same number of students whose academic performance is 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 and one student of class . 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 ( ) — number of students in both groups.
The second line contains sequence of integer numbers ( ), where is academic performance of the -th student of the group .
The third line contains sequence of integer numbers ( ), where is academic performance of the -th student of the group .
输出格式
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