-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy paththe_gift.py
More file actions
38 lines (29 loc) · 920 Bytes
/
the_gift.py
File metadata and controls
38 lines (29 loc) · 920 Bytes
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
32
33
34
35
36
37
38
def calculate_contributions(N, C, budgets):
budgets.sort()
total_budget = sum(budgets)
if total_budget < C:
return None
contributions = []
remaining_budget = C
for budget in budgets[:-1]:
contribution = min(budget, remaining_budget // (N - len(contributions)))
contributions.append(contribution)
remaining_budget -= contribution
contributions.append(remaining_budget) # Last person pays the remaining budget
return sorted(contributions)
if __name__ == "__main__":
# Read input
N = int(input())
C = int(input())
budgets = []
for _ in range(N):
budget = int(input())
budgets.append(budget)
# Calculate contributions
result = calculate_contributions(N, C, budgets)
# Print output
if result:
for contribution in result:
print(contribution)
else:
print("IMPOSSIBLE")