Help for 4.Social Distribution from Lists Advanced - More Exercises.
Здравейте, ако някой е получил 100/100 на тази задача, би ли споделил с мен как го е постигнал. Опитах какво ли не, но явно пропускам нещо съществено защото две проверки не минават (60/100) Ето и условието:
A core idea of several left-wing ideologies is that the wealthiest should support the poorest, no matter what and that is exactly what you are called to do for this problem.
On the first line you will be given the population (numbers separated by comma and space ", "). On the second line you will be given the minimum wealth. You have to distribute the wealth, so that there is no part of the population that has less than the minimum wealth. To do that, you should always take wealth from the wealthiest part of the population. There will be cases, where the distribution will not be possible. In that case, print "No equal distribution possible"
Example:
Input |
Output |
2, 3, 5, 15, 75 5 |
[5, 5, 5, 15, 70] |
2, 3, 5, 15, 75 20 |
[20, 20, 20, 20, 20] |
2, 3, 5, 45, 45 30 |
No equal distribution possible |
population = input().split(', ') wealth_level = int(input()) population_list = sorted(list(map(lambda x: int(x), population))) max_element = max(population_list) min_element = min(population_list) length_population_list = len(population_list) low_element = 0 if sum(population_list) / length_population_list < wealth_level or wealth_level == 0 or min_element >= wealth_level: print('No equal distribution possible') else: for element in population_list: if element <= wealth_level: min_element = element population_list.remove(element) population_list.insert(0, wealth_level) population_list.remove(max_element) max_element -= (wealth_level - min_element) population_list.append(max_element) else: element = element max_element = max(population_list) print(population_list)
Благодаря!