好丑
丑吐我了
但我只求AC了
还要去公司
想那个了
def dividePlayers(self, skill: List[int]) -> int:
summ = sum(skill)
if summ%(len(skill)//2) != 0:
return -1
target = sum(skill)//(len(skill)//2)
cnt = defaultdict(int)
for s in skill:
cnt[s] += 1
ans = 0
for s in skill:
if cnt[s] == 0:
continue
cnt[s] -= 1
if cnt[target-s] > 0:
cnt[target-s] -= 1
else:
return -1
ans += (target-s)*s
return ans