(calories []int, k int, lower int, upper int)
| 1 | package diet_plan_performance_1176 |
| 2 | |
| 3 | func dietPlanPerformance(calories []int, k int, lower int, upper int) int { |
| 4 | start := 0 |
| 5 | end := k - 1 |
| 6 | t := 0 |
| 7 | for i := start; i <= end; i++ { |
| 8 | t += calories[i] |
| 9 | } |
| 10 | |
| 11 | points := getPointsForT(t, lower, upper) |
| 12 | |
| 13 | for end < len(calories)-1 { |
| 14 | t = t - calories[start] |
| 15 | start++ |
| 16 | end++ |
| 17 | t = t + calories[end] |
| 18 | |
| 19 | points += getPointsForT(t, lower, upper) |
| 20 | } |
| 21 | |
| 22 | return points |
| 23 | } |
| 24 | |
| 25 | func getPointsForT(t, lower, upper int) int { |
| 26 | if t < lower { |