bank_cash = {
100: 0,
200: 3,
500: 1,
1000: 0,
2000: 4,
5000: 1,
}
def give_cash(sum):
if sum % 100 == 0:
count = 0
check_sum = 0
sorted_cash = sorted(bank_cash, reverse=True) # <-словари в питоне не сортируются,
check_dict = {} # только ключи в лист
for bank_note in sorted_cash:
if bank_cash[bank_note] == 0:
count += 1
continue
check_sum += (sum // bank_note)*bank_note
for i in range(count+1,len(sorted_cash)):
rest_sum = sum - check_sum
a = rest_sum // sorted_cash[i]
if (
bank_cash[sorted_cash[i]] == 0 or
a == 0
):
continue
elif a >= bank_cash[sorted_cash[i]]:
# БЛЯ НА 500 ТУТ СПОТЫКАЮСЬ СУКАААА ААА АА А АА АА А!!!!
check_sum += sorted_cash[i] * bank_cash[sorted_cash[i]]
check_dict[sorted_cash[i]] = bank_cash[sorted_cash[i]]
continue
elif rest_sum == 0:
break
count += 1
if check_sum != sum:
check_dict = {}
check_sum = 0
continue
else:
return check_dict
print(give_cash(6600))
YmFua19jYXNoID0gewogICAgMTAwOiAwLAogICAgMjAwOiAzLAogICAgNTAwOiAxLAogICAgMTAwMDogMCwKICAgIDIwMDA6IDQsCiAgICA1MDAwOiAxLAogICAgfQoKZGVmIGdpdmVfY2FzaChzdW0pOgogICAgaWYgc3VtICUgMTAwID09IDA6CiAgICAgICAgY291bnQgPSAwCiAgICAgICAgY2hlY2tfc3VtID0gMAogICAgICAgIHNvcnRlZF9jYXNoID0gc29ydGVkKGJhbmtfY2FzaCwgcmV2ZXJzZT1UcnVlKSAgICMgPC3RgdC70L7QstCw0YDQuCDQsiDQv9C40YLQvtC90LUg0L3QtSDRgdC+0YDRgtC40YDRg9GO0YLRgdGPLAogICAgICAgIGNoZWNrX2RpY3QgPSB7fSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICMgCdGC0L7Qu9GM0LrQviDQutC70Y7Rh9C4INCyINC70LjRgdGCCiAgICAgICAgZm9yIGJhbmtfbm90ZSBpbiBzb3J0ZWRfY2FzaDoKICAgICAgICAgICAgaWYgYmFua19jYXNoW2Jhbmtfbm90ZV0gPT0gMDoKICAgICAgICAgICAgICAgIGNvdW50ICs9IDEKICAgICAgICAgICAgICAgIGNvbnRpbnVlCiAgICAgICAgICAgIGNoZWNrX3N1bSArPSAoc3VtIC8vIGJhbmtfbm90ZSkqYmFua19ub3RlCiAgICAgICAgICAgIGZvciBpIGluIHJhbmdlKGNvdW50KzEsbGVuKHNvcnRlZF9jYXNoKSk6CiAgICAgICAgICAgICAgICByZXN0X3N1bSA9IHN1bSAtIGNoZWNrX3N1bQogICAgICAgICAgICAgICAgYSA9IHJlc3Rfc3VtIC8vIHNvcnRlZF9jYXNoW2ldCiAgICAgICAgICAgICAgICBpZiAoCiAgICAgICAgICAgICAgICAgICAgYmFua19jYXNoW3NvcnRlZF9jYXNoW2ldXSA9PSAwIG9yCiAgICAgICAgICAgICAgICAgICAgYSA9PSAwCiAgICAgICAgICAgICAgICAgICAgKToKICAgICAgICAgICAgICAgICAgICBjb250aW51ZQogICAgICAgICAgICAgICAgZWxpZiBhID49IGJhbmtfY2FzaFtzb3J0ZWRfY2FzaFtpXV06CiAgICAgICAgICAgICAgICAgICAgIyDQkdCb0K8g0J3QkCA1MDAg0KLQo9CiINCh0J/QntCi0KvQmtCQ0K7QodCsINCh0KPQmtCQ0JDQkNCQINCQ0JDQkCDQkNCQINCQINCQ0JAg0JDQkCDQkCEhISEKICAgICAgICAgICAgICAgICAgICBjaGVja19zdW0gKz0gc29ydGVkX2Nhc2hbaV0gKiBiYW5rX2Nhc2hbc29ydGVkX2Nhc2hbaV1dCiAgICAgICAgICAgICAgICAgICAgY2hlY2tfZGljdFtzb3J0ZWRfY2FzaFtpXV0gPSBiYW5rX2Nhc2hbc29ydGVkX2Nhc2hbaV1dCiAgICAgICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgICAgIGVsaWYgcmVzdF9zdW0gPT0gMDoKICAgICAgICAgICAgICAgICAgICBicmVhawogICAgICAgICAgICBjb3VudCArPSAxCiAgICAgICAgICAgIGlmIGNoZWNrX3N1bSAhPSBzdW06CiAgICAgICAgICAgICAgICBjaGVja19kaWN0ID0ge30KICAgICAgICAgICAgICAgIGNoZWNrX3N1bSA9IDAKICAgICAgICAgICAgICAgIGNvbnRpbnVlCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICByZXR1cm4gY2hlY2tfZGljdAoKcHJpbnQoZ2l2ZV9jYXNoKDY2MDApKQ==