Created
March 17, 2025 01:52
-
-
Save unilecs/ebf505863c07ff797cf3c59a0b9aa014 to your computer and use it in GitHub Desktop.
Задача: Оптимальное заполнение мешков (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def maximumBags(capacity, rocks, additionalRocks): | |
| # Вычитаем текущее количество камней из ёмкости | |
| capacity = [c - r for c, r in zip(capacity, rocks)] | |
| # Сортируем по возрастанию оставшегося места | |
| capacity.sort() | |
| result = 0 | |
| for space in capacity: | |
| if space > 0 and additionalRocks == 0: | |
| return result | |
| if space == 0: | |
| result += 1 | |
| elif space <= additionalRocks: | |
| additionalRocks -= space | |
| result += 1 | |
| return result | |
| # Пример использования | |
| capacity = [2, 3, 4, 5] | |
| rocks = [1, 2, 4, 4] | |
| additionalRocks = 2 | |
| print(maximumBags(capacity, rocks, additionalRocks)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment