参考及具体证明:https://blog.nowcoder.net/n/b5b3c86f177943bf9173333de3c027eb
思路:贪心,猜结论。我们要让损失的花朵最少,那么很容易想到贪心策略:越早运输损失大的牛越好,那该如何衡量损失大?应该用进行衡量,如果比值越大,那么我们要优先运输这个牛,以减少损失。所以说,我们就用自定义排序,按照比值进行递减排序,然后遍历一遍算结果,最终输出即可
代码:
import sys
input = lambda: sys.stdin.readline().strip()
import math
inf = 10 ** 18
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LI():
return input().split()
def LII():
return list(map(int, input().split()))
def LFI():
return list(map(float, input().split()))
fmax = lambda x, y: x if x > y else y
fmin = lambda x, y: x if x < y else y
isqrt = lambda x: int(math.sqrt(x))
'''
'''
def solve():
n = II()
cow = []
for _ in range(n):
t, d = MII()
t *= 2
cow.append((t, d))
cow.sort(key=lambda x: -(x[1] / x[0]))
ans = 0
time_step = 0
for t, d in cow:
ans += time_step * d
time_step += t
print(ans)
tt = 1
# t = II()
for _ in range(tt):
solve()

京公网安备 11010502036488号