Advertisement
simeonshopov

Social Distribution

Jan 15th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #!/usr/local/bin/python3.7
  2. # -*- coding: utf-8 -*import
  3.  
  4. pops = [int(x) for x in input().split(', ')]
  5. min_wealth = int(input())
  6.  
  7. if sum(pops) / len(pops) < min_wealth:
  8.     print('No equal distribution possible')
  9. else:
  10.     wealthiest = [x for x in pops if x > min_wealth][::-1]
  11.  
  12.     for rich in wealthiest:
  13.         filtered = [x for x in pops if x == rich]
  14.         idx = pops.index(filtered[0])
  15.  
  16.         for poor in pops:
  17.             if poor < min_wealth:
  18.                 filtered_ = [x for x in pops if x == poor]
  19.                 idx_ = pops.index(filtered_[0])
  20.                 dif = min_wealth - poor
  21.  
  22.                 if rich - dif >= min_wealth:
  23.                     rich -= dif
  24.                     poor += dif
  25.                     pops[idx_] = poor
  26.                     continue
  27.                 else:
  28.                     if rich == min_wealth:
  29.                         break
  30.                     else:
  31.                         dif = rich - min_wealth
  32.                         rich -= dif
  33.                         poor += dif
  34.                         # pops[idx_] = poor
  35.                         break
  36.  
  37.         pops[idx] = rich
  38.  
  39.     print(pops)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement