因为编辑问题,所以用图片代表题目,图片第一张是问题描述,第二张图片是例子


s = input(">>>")
l = list(map(int, s.split()))
l = sorted(l)
cost = []
while len(l) > 1:
cost.append((l[0], l[1]))
l = l[2:] + [l[0] + l[1]]
l = sorted(l)
print(cost, l)
print(sum([i + j for i, j in cost]))