Computer Science, asked by guaravkumar25101999, 7 months ago

monica has cooked n dishes and collected the data on the level of satisfaction for all the dishes from a guest. the guest returns an array, where the ith element of the array is the liking level of the ith dish. also, the time taken to cook the ith dish is i. like-to-time coefficient of a dish is calculated by multiplying the time taken to cook food with its liking level, i.e., input 2[i]. totally like-to-time coefficient is calculated by summing up all individual coefficients of dishes. you want the total like-to-time coefficient to be maximum. you can also remove some dishes, in which case, a new coefficient is calculated using the left dishes. find the maximum sum of all possible like-to-time coefficients.​

Answers

Answered by anjumanyasmin
22

Answer:

Reducing Dishes

Monica has cooked N dishes and collected the data on the level of satisfaction for all the dishes from a guest.

 {

     Arrays.sort(satisfaction);

     int len=satisfaction.length;

     if(satisfaction[len-1]<=0) return 0;

     int max=satisfaction[len-1];

     int base=max;

     for(int i=len-2;i>=0;i--)

     {

         int next=satisfaction[i]+max+base;

         if(next>=max)

         {

             max=next;

             base+=satisfaction[i];

         }

         else

             return max;

     }

Similar questions