Computer Science, asked by sushma552, 12 hours ago

The janitor of a high school is extremely efficient.By the end of each day, all of the school's waste isin plastic bags weighing between 1.01 pounds and3.00 pounds. All plastic bags are then taken to thetrash bins outside. One trip is described as selectinga number of bags which together do not weighmore than 3.00 pounds, dumping them in theoutside trash can and returning to the school. Giventhe number of plastic bags n, and the weights ofeach bag, determine the minimum number of tripsthe janitor has to make,​

Answers

Answered by nehaumesh894
0

Answer:

sorry i doesn't now the answer

Answered by shilpa85475
0

Input:

4

1.50

1.50

1.50

1.50  

Sample Output

2

Explanation:

The janitor will carry the first 2 plastic bags together and the 3rd and 4th together requiring only 2 trips.

def efficientJanitor(weight, n):

   weight.sort()

   left_i = 0

   trips = 0

   n = 3

   for i in range(n-1, -1, -1):

       if(weight[i] > 1.99):

           trips+=1

       elif(weight[i] <= 1.99):

           if(weight[i]+weight[left_i] <= 3):

               left_i+=1

           trips+=1

           if(left_i >= i):

               break

   return trips

n = int(input())

weight = list(map(float, input().split()))

trips = efficientJanitor(weight, n)

print(trips)

Similar questions