题解 | 数组计数维护

数组计数维护

https://www.nowcoder.com/practice/47ee4c040f1648fc9ef7732d35402676

import sys
line=sys.stdin.readline().strip()
test=int(line)
for _ in range(test):
     s,cnt=0,0
     a=sys.stdin.readline().split()
     n,k=int(a[0]),int(a[1])
     numstr=sys.stdin.readline().split()
     numl=list(map(int,numstr))
     for i in range(n):
        if numl[i]>=k:
            s+=numl[i]
        elif numl[i]==0 and s>=1:
            s-=1
            cnt+=1
     print(cnt)
    

     
        
   
       


全部评论

相关推荐

牛客nb666号:见天才的门槛罢了查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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