A community solar farm logs its daily energy output, in kilowatt-hours, for n consecutive days. Under its grid interconnection contract, auditors evaluate the farm's performance over every window of exactly k consecutive days: for each such window (there are n - k + 1 of them, sliding one day at a time), they sum that window's daily outputs. If a window's total output falls strictly below the contracted floor minOutput, the farm incurs a shortfall penalty of -1 point for that window. If the total strictly exceeds the surplus ceiling maxOutput, the farm earns a surplus bonus of +1 point. If the total lies anywhere between minOutput and maxOutput, inclusive, the window is neutral and contributes 0 points.
Compute the farm's total audit score, summed across every window.
Print a single integer: the total audit score summed over all n - k + 1 windows. The score may be negative, zero, or positive.
Example 1
Input
7 3 6 8 3 2 1 4 1 3 5
Expected
1
Explanation
With k=3 there are 5 windows: [3,2,1]=6 (equal to minOutput 6, neutral), [2,1,4]=7 (neutral), [1,4,1]=6 (neutral), [4,1,3]=8 (equal to maxOutput 8, neutral), [1,3,5]=9 (strictly above 8, +1). Total score = 0+0+0+0+1 = 1.
Example 2
Input
5 1 2 4 1 2 3 4 5
Expected
0
Explanation
With k=1 each day is its own window. Day 1: output 1, strictly below minOutput 2 -> -1. Days 2-4: outputs 2, 3, 4 are all within [2,4] -> 0 each. Day 5: output 5, strictly above maxOutput 4 -> +1. Total score = -1+0+0+0+1 = 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →