清北学堂 隔壁
/*两层循环 maxn minn记录最大值和最小值 */ #include<iostream> #include<cstdio> int const MAXN=1005; using namespace std; int n,m,maxn,minn; int t1[MAXN],t2[MAXN]; bool f1[MAXN],f2[MAXN]; int main() { freopen("neighbor.in","r",stdin); freopen("neighbor.out","w",stdout); 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]&&!f1[i]&&!f2[j]) { minn+=t1[i]; f1[i]=true; f2[j]=true; } } for (int i=1;i<=n;i++) if (!f1[i]) minn+=t1[i]; for (int i=1;i<=m;i++) if (!f2[i]) minn+=t2[i]; printf("%d %d",minn,maxn); fclose(stdin); fclose(stdout); return 0; }