A. Pupils Redistribution
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

思路:

  模拟;

来,上代码:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm> using namespace std; int if_z,n,ai[],bi[],vi[]; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} int main()
{
in(n);int pos,cur=,kol=;
for(int i=;i<=n;i++) in(pos),ai[pos]++;
for(int i=;i<=n;i++) in(pos),bi[pos]++;
for(int i=;i<=;i++)
{
vi[i]=ai[i]-bi[i];
vi[i]/=,cur+=vi[i];
if(vi[i]>) kol+=vi[i];
pos=abs(ai[i]-bi[i]);
if(pos%)
{
cout<<"-1";
return ;
}
}
if(cur==) cout<<kol;
else cout<<"-1";
return ;
}

AC日记——Pupils Redistribution Codeforces 779a的更多相关文章

  1. AC日记——Cards Sorting codeforces 830B

    Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  2. AC日记——Card Game codeforces 808f

    F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...

  3. AC日记——Success Rate codeforces 807c

    Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  4. AC日记——T-Shirt Hunt codeforces 807b

    T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  5. AC日记——Magazine Ad codeforces 803d

    803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...

  6. AC日记——Broken BST codeforces 797d

    D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...

  7. AC日记——Array Queries codeforces 797e

    797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...

  8. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

  9. AC日记——Vicious Keyboard codeforces 801a

    801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. MySQL8.0.12安装及配置

    一.下载 下载页面http://dev.mysql.com/downloads/mysql/ 选择系统平台后,点击download(根据系统选择64或32位) 二.配置 1.下载成功后,解压安装包到要 ...

  2. VMware12全新安装CentOS-6.9模板机(已优化)

    1.从安装系统开始准备 安装中添加网卡 eth0 ip 10.0.0.210 netmask 24 gateway 10.0.0.254 DNS servers 223.5.5.5 eth1 ip 1 ...

  3. 根据参数优化nginx的服务性能

    一.优化nginx服务的worker进程数 在高并发.高访问量的Web服务场景,需要事先启动好更多的nginx进程,以保证快速响应并处理大量并发用户的请求. 1).优化nginx进程对应的配置 优化n ...

  4. robotframework的列表与字典

    这里以Get Element Size为例,Selenium2Library返回的是列表,AppiumLibrary返回的是字典. 列表用 ${width}获取:字典用 &{ui}[width ...

  5. 【mac】【转发】Mac系统升级后,按大小写键没反应了,切换大小写的灯不亮了

    Mac系统升级后发现caps lock 锁定大小写的键,失灵了,居然可以用来切换输入法了,经过一排查后, 使用以下几种方法处理: 方式一:长按 caps lock 键,来切换大小写 方式二:caps ...

  6. Python基础——模块与包

    在Python中,可以用import导入需要的模块.包.库.文件等. 把工作路径导入系统路径 import os#os是工作台 import sys#sys是系统 sys.path.append(os ...

  7. python for data analysis chapter1~2

    Q1:numpy与series的区别:index Tab补全(任意路径Tab) 内省(函数:?显示文档字符串,??显示源代码:结合通配符:np.* load *?) %load .py ctrl-c( ...

  8. 强大的with语句

    上下文管理器对象存在的目的是管理 with 语句,就像迭代器的存在是为了管理 for 语句一样. with 语句的目的是简化 try/finally 模式.这种模式用于保证一段代码运行完毕后执行某项操 ...

  9. Service 回顾

    绑定本地service需要实现onBind()方法

  10. JAVA-基础(六) Java.serialization 序列化

    序 列 化 序列化(serialization)是把一个对象的状态写入一个字节流的过程. Serializable接口 只有一个实现Serializable接口的对象可以被序列化工具存储和恢复.Ser ...