Problem——A. Neko Finds Grapes——Codeforces

A. Neko Finds Grapes
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer ai written on it and the j-th key has an integer bj on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.

The j-th key can be used to unlock the i-th chest if and only if the sum of the key number and the chest number is an odd number. Formally, ai+bj≡1(mod2). One key can be used to open at most one chest, and one chest can be opened at most once.

Find the maximum number of chests Neko can open.

Input

The first line contains integers n and m (1≤n,m≤105) — the number of chests and the number of keys.

The second line contains n integers a1,a2,…,an (1≤ai≤109) — the numbers written on the treasure chests.

The third line contains m integers b1,b2,…,bm (1≤bi≤109) — the numbers written on the keys.

Output

Print the maximum number of chests you can open.

Examples

input

5 4
9 14 6 2 11
8 4 7 20

output

3

input

5 1
2 4 6 8 10
5

output

1

input

1 4
10
20 30 40 50

output

0

Note

In the first example, one possible way to unlock 3 chests is as follows:

Use first key to unlock the fifth chest,
Use third key to unlock the second chest,
Use fourth key to unlock the first chest.
In the second example, you can use the only key to unlock any single chest (note that one key can’t be used twice).

In the third example, no key can unlock the given chest.

思路:

这道题看上下的奇偶个数就可以了,上面的奇数比下面的偶数多或等于时,说明下面的偶数都有配对,否则,下面的偶数配对数量只能上面有多少给奇数配多少。同理,上面的偶数与下面的奇数配对也是一样的。

代码:

#include<iostream>
#include <ostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define dd double
#define mes(x,y) memset(x,y,sizeof(y))
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		int q1=0,q2=0,ou1=0,ou2=0,a,b;
		for(int i=0;i<n;i++){
			cin>>a;
			if(a%2==0){
				ou1++;
			}
			else{
				q1++;
			}
		}
		for(int i=0;i<m;i++){
			cin>>b;
			if(b%2==0){
				ou2++;
			}
			else{
				q2++;
			}
		}
		int sum=0;
		if(q1<ou2){
			sum+=q1;
		}
		else{
			sum+=ou2;
		}
		if(ou1<q2){
			sum+=ou1;
		}
		else{
			sum+=q2;
		}
		cout<<sum<<endl;
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值