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='')
找了半天错,没找到,各位朋友谁来帮忙一下!
标签:25,1020,map,python,storageNum,int,maxSize,split,input 来源: https://blog.csdn.net/qq_44833392/article/details/120405322