Description

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.

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

题意:交换两个组的学生,使得两个组的分数相同。

解法:自然需要符合一个分数出现次数为偶数,如果出现奇数不能平分。

然后计算两个组出现相同分数之差除以2,求得和/2就是结果

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
int maxn=;
int a[],b[];
map<int,int>p,q;
int main()
{
int n;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
q[a[i]]++;
}
for(int i=;i<=n;i++)
{
cin>>b[i];
p[b[i]]++;
}
int ans=;
for(int i=;i<=;i++)
{
if((p[i]+q[i])%)
{
cout<<"-1";
return ;
}
else
{
ans+=abs(p[i]-q[i])/;
}
}
cout<<ans/<<endl;
return ;
}

Codeforces Round #402 (Div. 2) A的更多相关文章

  1. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  2. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  3. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces Round #402 (Div. 2) A B C sort D二分 (水)

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding

    暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...

  7. Codeforces Round #402 (Div. 2) 题解

    Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...

  8. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  9. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

  10. Codeforces Round #402 (Div. 2) B

    Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...

随机推荐

  1. POJ2389 —— 高精度乘法

    直接上代码了: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib& ...

  2. java random配置修改

    不知道 报啥错的时候 ,改这个 vim /usr/java/latest/jre/lib/security/java.security 原值: securerandom.source=file:/de ...

  3. POJ1236 Network of Schools (强连通分量,注意边界)

    A number of schools are connected to a computer network. Agreements have been developed among those ...

  4. bootstrap table 根据单元格中的数据改变单元格的样式

    在bootstrap-table.js里面列属性 formatter就是用来格式化单元格的,其默认值是undefined 类型是function,function(value,  row, index ...

  5. Tensorflow基础知识

    基本知识 使用 TensorFlow, 你必须明白 TensorFlow: 使用图 (graph) 来表示计算任务. 在被称之为 会话 (Session) 的上下文 (context) 中执行图. 使 ...

  6. Java类加载器回顾

    Java类加载采用了全盘委托机制,默认加载类时子类先会委托给父类加载,但父类加载不到时,子类才会自己尝试加载类.这种机制可以有效防止一个类被加载多次,同时也一定程度上防止重写JDK自身的类[Java自 ...

  7. 洛谷P1119灾后重建——Floyd

    题目:https://www.luogu.org/problemnew/show/P1119 N很小,考虑用Floyd: 因为t已经排好序,所以逐个加点,Floyd更新即可: 这也给我们一个启发,如果 ...

  8. Ubuntu18.04 安装 JDK7

    直接下载jdk压缩包方式安装 1.官网下载JDK      地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363 ...

  9. HDU3065(AC自动机入门题)

    病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  10. 《Kubernetes权威指南第2版》学习(二)一个简单的例子

    1: 安装VirtualBox, 并下载CentOS-7-x86_64-DVD-1708.iso, 安装centOS7,具体过程可以百度. 2:开启centOS的SSH, 步骤如下: (1) yum ...