Untitled
unknown
python
a year ago
845 B
12
Indexable
def allocate_resources(performances, inc, dec):
n = len(performances)
# Get the unique performances in descending order to determine ranks
unique_performances = sorted(set(performances), reverse=True)
# Map each performance to its rank
performance_rank = {perf: rank + 1 for rank, perf in enumerate(unique_performances)}
# Count the number of servers with the same performance
performance_count = {}
for perf in performances:
performance_count[perf] = performance_count.get(perf, 0) + 1
# Calculate resource allocation for each server
allocations = []
for perf in performances:
rank = performance_rank[perf]
same_rank_count = performance_count[perf]
allocation = inc * (n + 1 - rank) - dec * same_rank_count
allocations.append(allocation)
return allocationsEditor is loading...
Leave a Comment