题解 | #超市里扫货#

超市里扫货

https://ac.nowcoder.com/acm/problem/244927

这题我认为python选手最好要用deque来模拟,不断popleft直到deque空了就行了。

from sys import stdin
from collections import deque
input = stdin.readline
n,v = map(int,input().split())
l = deque(map(int,input().split()))
cnt = 0
while l:
    tempv = v
    while l:
        if l[0] <= tempv:
            tempv -= l.popleft()
        else:
            break
    cnt += 1
print(cnt)
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务