题解 | #奖学金#

奖学金

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

参考大佬代码,写一下python的

import collections

while True:
    try:
        n, r, avg = map(int, input().split())
        score, time = 0, 0
        cost_time = []
        dic = collections.defaultdict(int)
        for _ in range(n):
            a, b = map(int, input().split())
            cost_time.append(b)
            dic[b] += r - a
            score += a
            
        cost_time = list(set(cost_time))
        while score < n * avg:
            for ti in sorted(cost_time):
                if (n * avg) - score <= dic[ti]:
                    time += ti * ((n * avg) - score)
                    score = n * avg
                    break
                else:
                    score += dic[ti]
                    time += ti * dic[ti]
            
        print(time)
        
    except:
        break

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务