問題 B: 相聚HNUCM校園食堂
5 4
10 65 23 67 80
5 15 60 90
#include<bits/stdc++.h>
#define swap(x, y) {int temp=x;x=y;y=temp;}
using namespace std;
const int N=1005;
int a[N];
int b[N];
bool cmp(int a,int b){
return a<b;
}
int main()
{
int m,n;
while (cin>>m>>n){
for(int i=0;i<m;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
sort(a,a+m);
sort(b,b+n);
int temp=0;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(abs(a[i]-b[j])<=5&&b[j]!=0&&a[i]!=0){
temp++;
b[j]=0;
a[i]=0;
}
}
}
cout<<temp*2<<endl;
}
return 0;
}