Computer Science, asked by chandana7311, 2 months ago

Explanation:
She should not cancel cooking the first dish, since total coefficient without canceling equals
1(-1)+2(3)+3[4) =17
If she would have canceled cooking the first dish, the coefficient would be 1(3)+2(4) = 11
Hence, she should cook all 3 dishes for maximum like-to-time coefficient possible.
Example 2:
input1:5
input2: (-1-9,0.5,-7)
Output: 14
Explanation:
Monica should cancel dishes with like value -9 and -7. then she would be left with the first
third and fourth dishes
So, the total like-to-time coefficient would be 1-1)+2(0)+3(5)=14, hence, the output.
meer
Chandana HP Support +1-650-5​

Answers

Answered by subhasispatra94
0

Answer:

def maxarr(n , arr ) :

   arr.sort(reverse=True)

   if arr[0]<1:

       return 0

   res = sum_of_elements = arr[0]

   i=1

   while i!= len(arr):

       sum_of_elements+=arr[i]

       if sum_of_elements >=0:

           res+=sum_of_elements

           i+=1

       else:

           return res

   return res

Explanation:

Similar questions