隔壁

 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define N 1005
using namespace std;
int n,m,maxn,minn;
int t1[N],t2[N];
bool f[N],f2[N];
int main ()
{
    scanf ("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
            scanf ("%d",&t1[i]);
    for (int i=1;i<=m;i++)
            scanf ("%d",&t2[i]);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            maxn+=min(t1[i],t2[j]);
            if (t1[i]==t2[j]&&!f[i]&&!f2[j])
            {
                minn+=t1[i];
                f[i]=1;
                f2[j]=1;
            }
        }
    for (int i=1;i<=n;i++)
        if (!f[i])
            minn+=t1[i];
    for (int i=1;i<=m;i++)
        if (!f2[i])
            minn+=t2[i];
    printf ("%d %d",minn,maxn);
    return 0;
}
View Code

 

posted @ 2016-10-05 21:16  外婆桥  阅读(127)  评论(0编辑  收藏  举报