You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
510 B
22 lines
510 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 3010;
|
|
const int INF = 0x3f3f3f3f;
|
|
int s[N], a[N];
|
|
int n, m;
|
|
int mi = INF;
|
|
|
|
int main() {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) {
|
|
cin >> a[i]; // 刺痛值
|
|
s[i] = s[i - 1] + a[i]; // 构建一维前缀和
|
|
}
|
|
|
|
for (int i = m; i <= n; i++)
|
|
mi = min(mi, s[i] - s[i - m]); // 求定区间和并取最小的一部分
|
|
// 输出最小值
|
|
cout << mi << endl;
|
|
return 0;
|
|
} |