题解 | 魔导模块的效能迭代

魔导模块的效能迭代

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

import sys
import math
from collections import defaultdict, Counter, deque
import heapq

# 总和最小
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# 优化差值最大的
# 堆吗?
sub = []
for i in range(n):
    mn = min(a[i] -  math.ceil(a[i] / 2), a[i] - b[i])
    heapq.heappush(sub, (-mn, i))

sm = sum(a)

while m > 0:
    # print(sub)
    sb, i = heapq.heappop(sub)

    sb = -sb

    sm -= sb
    a[i] = b[i] if sb == a[i] - b[i] else math.ceil(a[i] / 2)
    mn = min(a[i] - math.ceil(a[i] / 2), a[i] - b[i])
    heapq.heappush(sub, (-mn, i))

    m -= 1

print(sm)




全部评论

相关推荐

不愿透露姓名的神秘牛友
03-19 10:38
实力求职者:真的绷不住了,第一张霸总人设,第二张求生欲拉满
点赞 评论 收藏
分享
鱼专:别投了,我看到有人点了第二个链接投递,还没退出界面,不合适的邮件就发过来了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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