Respuesta :
The task here is to complete a function that gives the required result indicated in the question. [See the full question below]
What is the completed function of for the above program?
The completed function is given as;
def minimulHeaviestSetA(arr,n):
arr.sort(reverse=True)
x=0
for i in range(1,n):
if sum(arr[:i])>sum(arr[i:]):
x=i
break
return arr[:x][::-1]
n=int(input()) arr=list(map(int,input().split())) A=minimulHeaviestSetA(arr,n)
print(A)
Learn more about functions:
https://brainly.com/question/20476366
#SPJ1
Full question:
An Amazon Fulfillment Associate has a set of items that need to be packed into two boxes. Given an integer array of the item weights larr) to be packed, divide the item weights into two subsets, A and B. for packing into the associated boxes, while respecting the following conditions: The intersection of A and B is null The union A and B is equal to the original array.
The number of elements in subset A is minimal. The sum of A's weights is greater than the sum of B's weights. Return the subset A in increasing order where the sum of A's weights is greater than the sum of B's weights. If more than one subset A exists, return the one with the maximal total weight.
Example n=5 arr = 13,7,5,6, 2) The 2 subsets in arr that satisfy the conditions for Aare (5, 7) and (6, 7]:
A is minimal (size 2) • Surn(A) = (5 + 7) = 12 > Sum(B) = (2+ 3+6) = 11 • Sum(A) + (6 + 7) = 13 > Sum(B) = (2 + 3 + 5) - 10 •
The intersection of A and B is null and their union is equal to arr. . The subset A where the sum of its weight is maximal is [6.7).
Function Description Complete the minimal Heaviest Seta function.