1020 月饼 (25 分)python

'''
Author: 365JHWZGo
Description: 1020 月饼 (25 分)
Date: 2021-09-21 17:10:10
FilePath: \demo8.py
LastEditTime: 2021-09-21 20:48:27
LastEditors: 365JHWZGo
'''

kind, maxSize = map(int, input().split())
storageNum = []
totalPrice = []
price = []
profit = 0
if kind == 0 or maxSize == 0:
    profit = 0
else:
    storageNum.extend(map(int, input().split()))
    totalPrice.extend(map(int, input().split()))
    #当总量大于所有仓库的总量
    if sum(storageNum) <= maxSize:
        profit = sum(totalPrice)
    else:
        for i in range(kind):
            price.append([totalPrice[i] / storageNum[i], i])
        price = sorted(price, key=lambda x: x[0], reverse=True)
        for value, key in price:
            if storageNum[key] < maxSize:
                profit += totalPrice[key]
                maxSize -= storageNum[key]
            else:
                profit += (maxSize / storageNum[key]) * totalPrice[key]
                break
print('{0:.2f}'.format(profit), end='')

1020 月饼 (25 分)python
找了半天错,没找到,各位朋友谁来帮忙一下!

上一篇:苹果Mac Win10式任务栏工具:uBar


下一篇:1020: 两整数排序 Python