可以优化
先暴力求解了,由于数据量比较小。
#include <cstdio>
#include <iostream>
#include <string>
#include <unordered_map>
#include <stack>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1005;
int arr[N], brr[N];
int main(){
int n, m;
while(cin>>n>>m){
int res = 0x3f3f3f3f;
for(int i = 0; i < n; i++){
cin>>arr[i];
}
for(int i = 0; i < m; i++){
cin>>brr[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
res = min(res, abs(arr[i] - brr[j]));
}
}
cout<<res<<endl;
}
return 0;
}