水题,前缀和,然后扫一遍维护.
附ac代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, k, A[100010], B[100010];
int main()
{
cin >> N >> k;
for (int i = 0; i < N; i++) cin >> A[i];
B[0] = A[0];
for (int i = 1; i < N; i++) B[i] = A[i] + B[i - 1];
ll max = B[k -1];
for (int i = k; i < N; ++i)
{
if (B[i] - B[i - k] > max) max = B[i] - B[i - k];
}
cout << max <<endl;
return 0;
}