20分求调!
查看原帖
20分求调!
1772896
WindyValleys楼主2025/6/27 18:58

除了第一个点全是WA……SOS!!!

n,t=map(int,input().split(' '))
weight=[]
price=[]
cost=[]
sum=0
wholeweight=0
for i in range (n):
    a,b=map(int,input().split(' '))
    weight.append(a)
    price.append(b)
    c=price[i]/weight[i]
    cost.append(c)
test=dict(zip(cost,price))
test=sorted(test.items(),reverse=True)
for j in range (n):
    sum+=test[j][1]
    wholeweight+=weight[j]
    if wholeweight>t:
        sum-=test[j][0]*(wholeweight-t)
        break
print("{:.2f}".format(sum))

(Python求解,C也可以,C++超出本人学习范围)

2025/6/27 18:58
加载中...