您的位置:首页 > 编程语言 > Python开发

Python刷题集合——瞌睡

2020-02-02 17:22 417 查看

牛客网-瞌睡

Python 代码

def f(n,k,a,t):

# k>=n,整节课都保持清醒
if k>=n:
return sum(a)

"""
#将评分分为两部分:
#(1)一部分是没有叫醒服务,得到的评分,cur
#(2)一部分是叫醒一次,额外得到的评分,other
"""
cur=0
other=[0]
for i in range(n):
cur+=a[i]*t[i]
other.append(other[i]+a[i]*(1-t[i]))

M=0
for i in range(n):
if i+k-1<n:
M=max(M,other[i+k]-other[i])
else:
#越界
M=max(M,other[-1]-other[i])
return cur+M

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
t=list(map(int,input().split()))
print(f(n,k,a,t))
  • 点赞 1
  • 收藏
  • 分享
  • 文章举报
ysc1006 发布了14 篇原创文章 · 获赞 1 · 访问量 798 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: