python小白求助,为什么二分法后全是0,测试数据也是正确的

P1678 烦恼的高考志愿

z2106007726 @ 2022-03-24 21:02:54

m,n =map(int,input().split(" "))
school = list(map(int,input().split(" ")))
score = list(map(int,input().split(" ")))
school = sorted(school)
sum = 0
for x in score:
    l,r = 0,len(school)-1
    while l<r:
        mid = (l+r)//2
        if x<=school[mid]:
            r = mid
        else:
            l = mid+1
    sum += min(abs(x-school[l]),abs(x-school[l-1]))
print(sum)

|