题解 | 云服务资源调度

云服务资源调度

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

n = int(input())
costs = list(map(int, input().split()))
c = int(input())

costs.sort(reverse=True)

n_extra = 0
for cost in costs:
    if cost >= c:
        n_extra += 1
    else:
        break

server_usables = []

for cost in costs[n_extra:]:
    need_new = True
    for i, u in enumerate(server_usables):
        if u >= cost:
            server_usables[i] -= cost
            need_new = False
            break
    if need_new:
        server_usables.append(c - cost)
    # print(server_usables)
    
print(len(server_usables) + n_extra)

全部评论

相关推荐

Rac000n:淘天-客户运营部-AI研发工程师,智能客服方向,暑期实习招聘,欢迎联系
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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