★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: to dare (WeiGanTechnologies)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://github.com/strengthen/LeetCode
➤ original address: HTTPS: //www.cnblogs. com / strengthen / p / 11443476.html
➤ If the address is not a link blog Park Yong Shan Chi, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
A dieter consumes calories[i]
calories on the i
-th day. For every consecutive sequence of k
days, they look at T, the total calories consumed during that sequence of k
days:
- If
T < lower
, they performed poorly on their diet and lose 1 point; - If
T > upper
, they performed well on their diet and gain 1 point; - Otherwise, they performed normally and there is no change in points.
Return the total number of points the dieter has after all calories.length
days.
Note that: The total points could be negative.
Example 1:
Input: calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3 Output: 0 Explaination: calories[0], calories[1] < lower and calories[3], calories[4] > upper, total points = 0.
Example 2:
Input: calories = [3,2], k = 2, lower = 0, upper = 1 Output: 1 Explaination: calories[0] + calories[1] > upper, total points = 1.
Example 3:
Input: calories = [6,5,0,0], k = 2, lower = 1, upper = 5 Output: 0 Explaination: calories[0] + calories[1] > upper, calories[2] + calories[3] < lower, total points = 0.
Constraints:
1 <= k <= calories.length <= 10^5
0 <= calories[i] <= 20000
0 <= lower <= upper
Your friends are a fitness enthusiast. The preceding days, he set himself a fitness program. Now like you to help him assess the plan is reasonable.
He will table a plan of calories consumed, which calories[i]
gives you the friend at the i
total number of calories consumed day needs.
Statistical plan period is usually k
days, you need to calculate his every successive period of k
total calories consumed days T:
- If
T < lower
, then the plan is relatively poor, and lose 1 point; - If
T > upper
, then the plan is relatively good, and a score of 1; - Otherwise, the plan ordinary, score untouched.
Please return completed all the statistics calories.length
out days later as a result of assessment.
Note: Total may be negative.
Example 1:
Input: calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3 Output: 0 explanation: calories [0], calories [ 1] <lower the calories [3], calories [4]> upper, score = 0.
Example 2:
Input: calories = [3,2], k = 2, lower = 0, upper = 1 Output: 1 explains: calories [0] + calories [ 1]> upper, score = 1.
Example 3:
Input: calories = [6,5,0,0], k = 2, lower = 1, upper = 5 outputs: 0 explanation: calories [0] + calories [ 1]> upper, calories [2] + calories [3 ] <lower, out = 0.
prompt:
1 <= k <= calories.length <= 10^5
0 <= calories[i] <= 20000
0 <= lower <= upper