示例1
输入:
10 2
1 1 2
120 20
90 10
输出:
540
说明:
总共10天时间,路上花费要4天,还有6天可以用来卖唱;
在第一座城市卖唱3天,赚钱120 + 100 + 80 = 300
在第二座城市卖唱3天,赚90 + 80 + 70 = 240
共计:300 + 240 = 540
# 输入总天数t, 中间经过的城市个数n
t, n = list(map(int, input().strip().split()))
# 输入城市间行程 耗费的时间
days_on_way = list(map(int, input().strip().split()))
# 供卖唱的天数
days_for_sing = t - sum(days_on_way)
# 输入中间经过的每个城市的挣钱的 M D
matrix = []
for i in range(n):
matrix.append(list(map(int, input().strip().split())))
print(matrix)
# 列出经过的每个城市每天卖唱的钱
money_list = []
for i in range(n):
m, d = matrix[i]
j = 0
while True:
if j >= days_for_sing or m <= 0:
break
else:
money_list.append(m)
m -= d # 挣钱 减少
j += 1 # 天数增加
# money_list 降序排序
money_list.sort(key=lambda i : -i)
print(money_list)
# 按照卖唱的天数,从最大依次取钱
result = 0
i = 0
while True:
if i >= days_for_sing:
break
else:
result += money_list[i]
i += 1
print(result)