Problems > Coldest Stretch

Coldest Stretch

Difficulty: 1200 3000 ms 128 MB

sliding-window

Daily temperatures are given. Find the starting day (1-based) of the K-day stretch with the smallest total temperature; on ties pick the earliest start.

Input: the first line has N and K; the second line has N integers (temperatures).

Output: the 1-based starting index of the minimum-sum window (earliest on ties).

Constraints:

  • 1 ≤ K ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
6 2
5 1 1 4 0 3
Output 1
2
Input 2
3 3
1 2 3
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.