-
Notifications
You must be signed in to change notification settings - Fork 0
/
CF-160A.py
31 lines (23 loc) · 920 Bytes
/
CF-160A.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
COIN_MAXIMUM_VALUE = 100
input()
amount_of_money = 0
coins_grouped_by_value = [0] * COIN_MAXIMUM_VALUE
for coin_value in input().split():
coin_value = int(coin_value)
coins_grouped_by_value[coin_value - 1] += 1
amount_of_money += coin_value
sorted_coins = []
for i in range(COIN_MAXIMUM_VALUE - 1, -1, -1):
number_of_coins_of_current_value = coins_grouped_by_value[i]
if number_of_coins_of_current_value != 0:
sorted_coins += [i + 1] * number_of_coins_of_current_value
remaining_money = amount_of_money
twin_number_of_coins_collected = twin_collected_money = 0
current_coin_index = 0
while twin_collected_money <= remaining_money:
current_coin_value = sorted_coins[current_coin_index]
twin_number_of_coins_collected += 1
twin_collected_money += current_coin_value
remaining_money -= current_coin_value
current_coin_index += 1
print(twin_number_of_coins_collected)