题解 | 云服务资源调度
云服务资源调度
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)
查看3道真题和解析