Loading... ![5-31.png][1] [1]: http://mioe.xyz/usr/uploads/2021/05/33685418.png coins, capacity = map(int, input().split()) emt = [] sum_coin = 0.0 for i in range(coins): temp_weight, temp_coin = map(int, input().split()) emt.append({'coin': temp_coin, 'weight': temp_weight, 'avg': temp_coin/temp_weight}) emt.sort(key=lambda emt_d: emt_d['avg'], reverse=True) for i in range(len(emt)): if capacity >= emt[i]['weight']: sum_coin += emt[i]['coin'] capacity -= emt[i]['weight'] elif capacity < emt[i]['weight'] and capacity != 0: sum_coin += emt[i]['avg'] * capacity break print('%.2f' % sum_coin) Last modification:May 31, 2021 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed