P1614 The Heartache of Love and Sorrow

Background

(This problem hides two song titles. See if you can find them~~~). "The Story of 'Love and Sorrow', Vol. 1 · heartache", Chapter 1. In "Wo Wei Ge Kuang", Wu Sikai's hit song "Dancing Moonlight" actually did not beat Sa Dingding. The guru "Ai Yu Chou" feels heartbroken~~~ Also, some sad things have happened lately, all of which make the heart ache (it has really been annoying lately).

Description

Recently there are $n$ unpleasant events, and each one has a positive integer sting value (his tolerance is extremely low). The guru "Ai Yu Chou" wants to know the minimum sum of $m$ consecutive sting values. Because he is busy, he asks you to write a program to tell him.

Input Format

The first line contains two space-separated integers, $n$ and $m$. Lines $2$ to $n + 1$ each contain one integer. For $i = 1, 2, \ldots, n$, line $i + 1$ contains an integer $a_i$, the sting value of the $i$-th event.

Output Format

Output one line with a single integer: the minimum sum of any $m$ consecutive sting values.

Explanation/Hint

Constraints - For $30\%$ of the testdata, it is guaranteed that $n \leq 20$. - For $60\%$ of the testdata, it is guaranteed that $n \leq 100$. - For $90\%$ of the testdata, it is guaranteed that $n \leq 10^3$. - For $100\%$ of the testdata, it is guaranteed that $0 \leq m \leq n \leq 3 \times 10^3$, $1 \leq a_i \leq 100$. Translated by ChatGPT 5