We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hope this works for you
def equal(arr):
min_operations = float('inf')
# Find the minimum number of chocolates in the array
min_chocolates = min(arr)
# Iterate from the minimum chocolates to 0
for target in range(min_chocolates, -1, -1):
operations = 0
# Calculate the operations needed to reach the target for each colleague
for chocolates in arr:
diff = chocolates - target
operations += (diff // 5) + ((diff % 5) // 2) + ((diff % 5) % 2)
# Update the minimum operations
min_operations = min(min_operations, operations)
return min_operations
Input handling
t = int(input()) # Number of test cases
for _ in range(t):
n = int(input()) # Number of colleagues
arr = list(map(int, input().split())) # Initial distribution of chocolates
result = equal(arr)
print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
Hope this works for you def equal(arr): min_operations = float('inf')
Input handling
t = int(input()) # Number of test cases for _ in range(t): n = int(input()) # Number of colleagues arr = list(map(int, input().split())) # Initial distribution of chocolates result = equal(arr) print(result)