python双指针,没超时但16分qaq
查看原帖
python双指针,没超时但16分qaq
811743
JerryWayne7楼主2023/7/20 14:24
n,c = map(int,input().split())
lst = list(map(int,input().split()))
lst.sort(reverse=True)
count = 0
p1 = 0
p2 = 1
while True:
    a = lst[p1]
    b = lst[p2]
    num = a-b
    if num<c:
        p2+=1
    elif num>c:
        p1+=1
    else:
        count+=1
        if lst[p1]==lst[p1+1]:
            count+=1
            p1+=1
            if lst[p2] == lst[p2 + 1]:
                count += 1
                p2+=1
        elif lst[p2]==lst[p2+1]:
            count+=1
        p2+=1
    if p2>=n-1:
        break
print(count)
2023/7/20 14:24
加载中...