/*

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

*/

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

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

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

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[], b[];
int x[], y[];
int main()
{
    int n;
    cin >> n;
    for(int i = ; i < n; i++)
    {
        cin >> a[i];
        x[a[i]] ++;
    }
    for(int i = ; i < n; i++)
    {
        cin >> b[i];
        y[b[i]] ++;
    }
    for(int i = ; i <= ; i++)
    {
        if((x[i] + y[i]) % != )
        {
            cout << "-1" << endl;
            return ;
        }
    }
    int aim = ;
    for(int i = ; i <= ; i++)
    {
        aim += abs(x[i] - y[i]) / ;
    }
    cout << aim / << endl;
    return ;
}

779A Pupils Redistribution的更多相关文章

  1. CodeForces 779A Pupils Redistribution

    简单题. 因为需要连边的人的个数一样,又要保证和一样,所以必须每个数字的个数都是一样的. #include<map> #include<set> #include<cti ...

  2. AC日记——Pupils Redistribution Codeforces 779a

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

  3. 【codeforces 779A】Pupils Redistribution

    [题目链接]:http://codeforces.com/contest/779/problem/A [题意] 让你把两个组的5个人的数目都变成一样的. 支持交换操作; 问你最少需要交换几次. [题解 ...

  4. CF779A(round 402 div.2 A) Pupils Redistribution

    题意: In Berland each high school student is characterized by academic performance — integer value bet ...

  5. 【推导】Codeforces Round #402 (Div. 2) A. Pupils Redistribution

    一次交换,会让Group A里面的某个数字的数量-1,另一个数字的数量+1:对Group B恰好相反. 于是答案就是xigma(i=1~5,numA[i]-numB[i]>0)(numA[i]- ...

  6. Codeforces #402

    目录 Codeforces #402 Codeforces #402 Codeforces 779A Pupils Redistribution 链接:http://codeforces.com/co ...

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

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

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

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

随机推荐

  1. 关于VS+ImageWatch在线调试问题

    1.使用VS肯定离不开在线调试 2.使用Opencv在VS下进行图像处理,那肯定少不了Image Watch 这两个软件在线调试都存在大坑,弄得精疲力尽才找到解决办法!!! 以下问题都可以通过这个设置 ...

  2. python入门-测试代码

    断言 测试函数 def get_formatted_name(first,last): """generate a neatly formattef full name& ...

  3. ASCII和万国码

    ASCII和万国码 什么是ASCII 计算机的起初是使用内存中的0101来表示数和机器码.如何用内存中的bit来表示文本一直困扰着人们,毕竟人类主要的信息展示是文字,而不是苦涩的0101.后来ASCI ...

  4. hive 上篇

    hive 是以hadoop为基础的数据仓库,使用HQL查询存放在HDFS上面的数据,HSQL是一种类SQL的语句,最终会被编译成map/reduce,HSQL可以查询HDFS上面的数据:不支持记录级别 ...

  5. three添加和移除对象

    创建场景在第一章的地方就讲过怎么样创建一个最基本的场景,这里不重复了html:部分 <!doctype html><html lang="en"><h ...

  6. IOUtils总结

    参考:https://www.cnblogs.com/xing901022/p/5978989.html 常用的静态变量 在IOUtils中还是有很多常用的一些变量的,比如换行符等等 public s ...

  7. 3.mybatis实战教程(mybatis in action)之三:实现数据的增删改查

    转自:https://blog.csdn.net/tangruyi1992/article/details/52583910 前面已经讲到用接口的方式编程.这种方式,要注意的一个地方就是.在User. ...

  8. nodejs 获取文件夹中所有文件、图片 名

    //获取项目工程里的图片 var fs = require('fs');//引用文件系统模块 var image = require("imageinfo"); //引用image ...

  9. Spring Boot 入门搭建

    一.前言 Spring Boot 的设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 二.环境搭建 创建一个 ...

  10. UI5-文档-2.1-使用OpenUI5开发应用

    使用OpenUI5和您选择的开发环境(编辑器和Web服务器)开发应用程序.您可以下载所有的源代码,也可以参考OpenUI5的在线版本. 下载OpenUI5 下载和安装OpenUI5的默认方式是从htt ...