题解 | #罪犯转移#

罪犯转移

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实现。

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
字节一直是我的白月光,考虑到转正还是拒了日常实习。
从今天开始狠狠卷JV...:为什么你释放的offer没流到我头上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务