题意:

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 nstudents. 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.

Input

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 a1, a2, ..., an (1 ≤ ai ≤ 5), where ai is academic performance of the i-th student of the group A.

The third line contains sequence of integer numbers b1, b2, ..., bn (1 ≤ bi ≤ 5), where bi is academic performance of the i-th student of the group B.

Output

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

Examples
input
4
5 4 4 4
5 5 4 5
output
1
input
6
1 1 1 1 1 1
5 5 5 5 5 5
output
3
input
1
5
3
output
-1
input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
output
4

思路:

构造。

实现:

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; int n, tmp, ca[], cb[];
int main()
{
cin >> n;
for (int i = ; i < n; i++)
{
scanf("%d", &tmp);
ca[tmp]++;
}
for (int i = ; i < n; i++)
{
scanf("%d", &tmp);
cb[tmp]++;
}
int cnt = ;
bool flag = true;
for (int i = ; i <= ; i++)
{
tmp = abs(cb[i] - ca[i]);
if (tmp & )
{
flag = false;
break;
}
cnt += tmp;
}
if (!flag)
cout << "-1" << endl;
else
cout << cnt / + cnt % / << endl;
return ;
}

最新文章

  1. codevs1257 打砖块
  2. jffs2和yaffs2文件系统制作工具的编译与使用
  3. tomcat本地部署war包的方式
  4. sql server 事务处理
  5. android lsitview setOnItemLongClickListener 无效或不执行
  6. NVelocity模板引擎的使用
  7. poj3169 最短路(差分约束)
  8. 简单的算法题, Find Minimum in Rotated Sorted Array 的Python实现。
  9. [译]脱离jQuery,使用原生Ajax
  10. erlang 练手 进程环
  11. C# Interface显式实现和隐式实现
  12. python装饰器 &amp; flask 通过装饰器 实现 单点登录验证
  13. [DeeplearningAI笔记]ML strategy_2_1误差分析
  14. Kestrel:Net Core的跨平台服务器
  15. OCM_第一天课程:OCM课程环境搭建
  16. 【Maven】Project configuration is not up-to-date with pom.xml错误解决方法
  17. oracle中去掉回车换行空格的方法详解
  18. ubuntu16安装及嵌入式开发环境搭建
  19. [转]NancyFx/Nancy
  20. 9. Swarm mode

热门文章

  1. redis03----集合 set 相关命令
  2. Codility经典算法题之九:MissingInteger
  3. POJ3621 Sightseeing Cows 最优比率环 二分法
  4. HDU1241 Oil Deposits —— DFS求连通块
  5. AFNetworking源码的学习
  6. Sorting a Three-Valued Sequence
  7. Prime Cryptarithm
  8. FINDSTR 命令使用详解
  9. [转]Python+Selenium之expected_conditions:各种判断(上)
  10. class.forName()和.class有什么区别?