第一次cf经历A. Neko Finds Grapes

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.
题目链接

#include<bits/stdc++.h>
#define maxn 101000
using namespace std;
int main()
{
    long long  a[maxn],b[maxn];
    long long  m,n,sum1=0,sum2=0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        a[i]%=2;
        sum1+=a[i];
    }
    for(int i=0;i<m;i++)
    {
        scanf("%lld",&b[i]);
        b[i]%=2;
        sum2+=b[i];
    }
    long long  cnt=0;
    cnt=min(sum1,m-sum2)+min(sum2,n-sum1);
    if(cnt>n) cnt=n;
    printf("%lld\n",cnt);
    return 0;
}
全部评论

相关推荐

今天投了小鹏,收到了AI面,大概会问哪些啊?
期末一定及格:总共4个部分,心理测评、行测、然后就是问岗位、对岗位的理解、过往遇到了哪些难点怎么解决,很简单,没有什么特别专业的问题,都是一些综合素质相关的
小鹏汽车AI面6人在聊
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务