#K9456. Minimum Difficulty Sum

    ID: 38668 Type: Default 1000ms 256MiB

Minimum Difficulty Sum

Minimum Difficulty Sum

You are given an array of n integers, where each integer represents the difficulty factor of a segment. Your task is to choose exactly k consecutive segments such that the sum of their difficulty factors is minimized. Mathematically, you need to find:

[ \min_{1 \leq i \leq n-k+1} \left( \sum_{j=i}^{i+k-1} a_j \right) ]

where (a_j) represents the difficulty factor of the j-th segment. Read the input from standard input and print the result to standard output.

inputFormat

The first line contains two space-separated integers, n and k, where n is the number of segments and k is the length of the contiguous subsequence. The second line contains n space-separated integers representing the difficulty factors of the segments.

outputFormat

Output a single integer, which is the minimum sum of any contiguous subsequence of length k.## sample

6 3
5 3 2 6 8 4
10