bc2_cryeggy @ 2022-12-10 14:48:06
#include<bits/stdc++.h>
using namespace std;
int m, n, a[100010], b[100010], res = 0;
int main()
{
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 + 0, a + m);
for(int i=0; i<n; i++)
{
int l = 0, r = m - 1, ans = 1e6 + 10;
while(l < r)
{
int mid = (l + r) / 2;
if(a[mid] >= b[i]) ans = min(ans, abs(b[i] - a[mid])), r = mid;
else l = mid + 1, ans = min(ans, abs(b[i] - a[mid]));
}
res += ans;
}
printf("%d", res);
return 0;
}
by IsFrog @ 2022-12-10 15:16:32
不能这样吧。。。
by IsFrog @ 2022-12-10 15:20:57
你不怕被发现吗。。。