Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.7
- # -*- coding: utf-8 -*import
- pops = [int(x) for x in input().split(', ')]
- min_wealth = int(input())
- if sum(pops) / len(pops) < min_wealth:
- print('No equal distribution possible')
- else:
- wealthiest = [x for x in pops if x > min_wealth][::-1]
- for rich in wealthiest:
- filtered = [x for x in pops if x == rich]
- idx = pops.index(filtered[0])
- for poor in pops:
- if poor < min_wealth:
- filtered_ = [x for x in pops if x == poor]
- idx_ = pops.index(filtered_[0])
- dif = min_wealth - poor
- if rich - dif >= min_wealth:
- rich -= dif
- poor += dif
- pops[idx_] = poor
- continue
- else:
- if rich == min_wealth:
- break
- else:
- dif = rich - min_wealth
- rich -= dif
- poor += dif
- # pops[idx_] = poor
- break
- pops[idx] = rich
- print(pops)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement