Loading... ## 题目 ##  ## 思路 很简单的二分查找,关键在于l<r-1模糊查找,找到了最接近的两个数,再比较差的绝对值,找到绝对值最小的那个加上去。 但是Python这么做奇慢。。 ## 题解 ```Python m,n = map(int,input().split()) uni = list(map(int,input().split())) std = list(map(int,input().split())) uni.sort() ans = 0 mid = 0 for i in range(n): l = 0 r = m - 1 while(l<r-1): mid = (l + r) // 2 if uni[mid] <= std[i]: l = mid elif uni[mid] > std[i]: r = mid ans += min(abs(uni[l] - std[i]),abs(uni[r] - std[i])) print(ans) ``` Last modification:March 10, 2022 © Allow specification reprint Support Appreciate the author WeChat Like 0 如果觉得我的文章对你有用,请随意赞赏