#P1614. Minimum Contiguous Subarray Sum

    ID: 14900 Type: Default 1000ms 256MiB

Minimum Contiguous Subarray Sum

Minimum Contiguous Subarray Sum

Given n events each with a positive integer "pain value", and a positive integer m, find the minimum sum of any contiguous subarray of length m. In other words, given an array \(A_1, A_2, \dots, A_n\), compute:

\(\min_{1 \leq i \leq n-m+1} \sum_{j=i}^{i+m-1}{A_j}\)

inputFormat

The input contains two lines:

  • The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 105).
  • The second line contains n positive integers representing the pain values, each is at most 109.

outputFormat

Output a single integer representing the minimum sum of any contiguous subarray of length m.

sample

5 2
3 2 1 2 3
3

</p>