Bronze
Batch
Editorial available
Milking Window
/milking-window
Version
v1
Published
Apr 23, 2026, 10:56 PM
Updated
Apr 23, 2026, 10:56 PM
Testsets
1
Statement
Rendered as plain statement text from the published version.
# Milking Window
## Problem Statement
Bessie has been recording milk production from each of her N cows over several time periods. She wants to understand which consecutive period gives the maximum total milk output.
Given N milk production values and a window size K, find the maximum total milk produced in any consecutive K time periods.
## Input Format
The first line contains two integers N and K:
- N: the number of time periods (1 ≤ N ≤ 100,000)
- K: the window size (1 ≤ K ≤ N)
The second line contains N integers representing the milk output for each period (1 ≤ value ≤ 1,000).
## Output Format
A single integer: the maximum total milk output across all possible consecutive windows of size K.
## Constraints
- 1 ≤ N ≤ 100,000
- 1 ≤ K ≤ N
- 1 ≤ milk output ≤ 1,000
## Sample
**Input:**
```
6 3
2 3 5 1 4 6
```
**Output:**
```
11
```
**Explanation:**
Bessie has 6 time periods with milk outputs: 2, 3, 5, 1, 4, 6.
With a window size of K=3, we check all consecutive windows of 3 periods:
- Periods 1-3: 2 + 3 + 5 = 10
- Periods 2-4: 3 + 5 + 1 = 9
- Periods 3-5: 5 + 1 + 4 = 10
- Periods 4-6: 1 + 4 + 6 = **11** ← maximum
The answer is 11.