提示如下:
1.将两序列合并为一个序列,并排序,为列表Source
2.拿出最大元素Big,次大的元素Small
3.在列表Source中找出最大值和最小值,将最大值和Small放在一起组成列表 c,将最小值和Big放在一起组成列表 d
4.再在列表Source中找出最大值和最小值,重新计算sum(c)和sum(d),将最大值放在重新计算后和最小的列表里面,最小值放在另一个列表里面
5.重复第4步,直到分完
a = [2,6,7,9,1]
b = [3,8,10,5,0]
def shen():
Source = list(a+b)
Source.sort(reverse=True)
c = []
d = []
while Source:
c.append(Source.pop(0))
c.append(Source.pop())
for i in Source:
d.append(Source.pop(0))
d.append(Source.pop())
break
return f'sum(a) 和 sum(b)的差值最小为:{sum(c) - sum(d)}'
a = shen()
print(a)