This commit is contained in:
nik
2025-10-01 22:55:09 +03:00
parent 4d0ece634b
commit 74e98c37c4
591 changed files with 20286 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
def greedy_thief(weights, values, M, K):
items = list(zip(weights, values))
items.sort(key=lambda x: x[1] / x[0], reverse=True)
cap = M * K
total_value = 0
chosen = []
for w, v in items:
if w <= cap:
chosen.append((w, v))
cap -= w
total_value += v
return total_value, chosen
if __name__ == "__main__":
weights = [2, 3, 4, 5, 9, 7, 3]
values = [3, 4, 5, 8, 10, 7, 6]
M = 2
K = 10
print(greedy_thief(weights, values, M, K))