package leetcode;

/**
 * https://leetcode.com/problems/diet-plan-performance/
 */
public class Problem1176 {
    public int dietPlanPerformance(int[] calories, int k, int lower, int upper) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1176 prob = new Problem1176();
        System.out.println(prob.dietPlanPerformance(new int[]{1, 2, 3, 4, 5}, 1, 3, 3)); // 0
        System.out.println(prob.dietPlanPerformance(new int[]{3, 2}, 2, 0, 1)); // 1
        System.out.println(prob.dietPlanPerformance(new int[]{6, 5, 0, 0}, 2, 1, 5)); // 0
    }
}

@@ -197,401 +197,523 @@
     
-// TODO%0A        return 0
+int answer = 0;%0A        int%5B%5D sums = new int%5Bcalories.length%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1176 prob = new Problem1176();%0A        System.out.println(prob.dietPlanPerformance(new int%5B%5D%7B1, 2, 3, 4, 5%7D, 1, 3, 3)); // 0%0A        System.out.println(prob.dietPlanPerformance(new int%5B%5D%7B3, 2%7D, 2, 0, 1)); // 1%0A        System.out.println(prob.dietPlanPerformance(new int%5B%5D%7B6, 5, 0, 0%7D, 2, 1, 5)); // 0
+for (int i = 0; i %3C k; i++) %7B%0A            sums%5Bk - 1%5D += calories%5Bi%5D;%0A        %7D%0A        for (int i = 0, j = k; j %3C calories.length; i++, j++) %7B%0A            sums%5Bj%5D = sums%5Bj - 1%5D + calories%5Bj%5D - calories%5Bi%5D;%0A        %7D%0A        for (int i = k - 1; i %3C sums.length; i++) %7B%0A            if (sums%5Bi%5D %3C lower) %7B%0A                answer--;%0A            %7D else if (sums%5Bi%5D %3E upper) %7B%0A                answer++;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1176