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

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
const int INF = 0x3f3f3f3f;
2 years ago
int s[N], a[N];
int n, m;
int mi = INF;
2 years ago
int main() {
cin >> n >> m;
2 years ago
for (int i = 1; i <= n; i++) {
cin >> a[i]; // 刺痛值
s[i] = s[i - 1] + a[i]; // 构建一维前缀和
2 years ago
}
2 years ago
for (int i = m; i <= n; i++)
mi = min(mi, s[i] - s[i - m]); // 求定区间和并取最小的一部分
// 输出最小值
2 years ago
cout << mi << endl;
2 years ago
return 0;
}