Answer to Question #291660 in Java | JSP | JSF for Pavan

Question #291660

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.​

1
Expert's answer
2022-01-28T10:32:35-0500
public class Main {
    public static void main(String[] args) {
        int[] likingLevels = {4, 6, -3, 9, -1, 0, -4, 8};
        int max = 0;
        for (int i = 0; i < likingLevels.length; i++) {
            if (i * likingLevels[i] >= 0) {
                max += i * likingLevels[i];
            }
        }
        System.out.println(max);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS