Echo5201 @ 2024-11-08 17:17:35
m,n=map(int,input().split())
xx = list(map(int,input().split()))#学校
xs = list(map(int,input().split()))#学生
xs.sort()#排序
xx.sort()
s=0
for i in xs:#学生
ans=999999
left=0
right=len(xx)-1
while(left<=right):
mid = (left+right)//2
if(xx[mid]==i):
ans=0
break
elif(xx[mid]<i):
ans = min(ans,abs(xx[mid]-i))#最小值
left = mid+1
elif(xx[mid]>i):
ans = min(ans,abs(xx[mid]-i))
right = mid-1
s=s+ans
print(s)
by bsdsdb @ 2024-11-08 17:21:24
希丰展使md
by LionBlaze @ 2024-11-08 17:25:36
@Echo5201
by Echo5201 @ 2024-11-08 17:25:56
@0x28202e202e29 大佬这是什么呢
by LionBlaze @ 2024-11-08 17:35:46
@Echo5201 希望更丰富的展现?使用 Markdown、KaTeX。
by Echo5201 @ 2024-11-08 18:34:13
@LionBlaze 欧克 我这就去 不好意思哈
by Echo5201 @ 2024-11-08 18:51:36
m,n=map(int,input().split())
xx = list(map(int,input().split()))
xs = list(map(int,input().split()))
xs.sort()
xx.sort()
s=0
ans=999999
left=0
right=len(xx)-1
while(left<=right):
mid = (left+right)//2
if(xx[mid]==i):
ans=0
break
elif(xx[mid]<i):
#最小值
ans = min(ans,abs(xx[mid]-i))
left = mid+1
elif(xx[mid]>i):
ans = min(ans,abs(xx[mid]-i))
right = mid-1
s=s+ans
by Echo5201 @ 2024-11-08 18:51:58
@LionBlaze 这样可以吗
by Echo5201 @ 2024-11-08 18:52:19
@0x28202e202e29 谢谢呢 这个可以吗
by LionBlaze @ 2024-11-08 18:53:34
?
by Echo5201 @ 2024-11-08 18:59:11
@LionBlaze 哈哈哈 前面不是说我代码发的不清楚吗 不是这个意思吗