题解 | #罪犯转移#

罪犯转移

https://www.nowcoder.com/practice/b7b1ad820f0a493aa128ed6c9e0af448

while True:
    try:
        line = input()
        if not line:
            break
        n, t, c = list(map(int, line.strip().split()))
        crime_values = list(map(int,input().strip().split()))
        window_sum = 0
        ans = 0
        for idx, a in enumerate(crime_values):
            if idx < c:
                window_sum += a
                if idx == c-1 and window_sum <= t:
                    ans += 1
                continue
            window_sum = window_sum + a - crime_values[idx-c]
            if window_sum <= t:
                ans += 1

        print(ans)
    except:
        break

滑动窗口

python3实现。

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务