求教,为什么最后一个测试点死活过不去?
查看原帖
求教,为什么最后一个测试点死活过不去?
1170758
Coicce楼主2024/4/12 20:38

下面是我的代码:

n,x = map(int,input().split())
wide = n
a = [int(num) for num in input().split()]
wide = 1

sum = [0] * (n - 1)
sum[0] = a[0]
while wide < n - 1:
    sum[wide] = sum[wide - 1] + a[wide]
    wide += 1
#这里记录了前缀和
def bisection(left,right):
    return (left + right) // 2
def boolcheck(length):
    for i in range(length, n - 1):
        if sum[i] - sum[i - length] < 2 * x:
            return 0
    return 1
#判断函数
left  = 1
right = n - 1
while left <= right:
    mid = bisection(left,right)
    if boolcheck(mid):
        right = mid - 1
    else:
        left  = mid + 1
print(left)
2024/4/12 20:38
加载中...