#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int sum = 0;
    for (int i = 0; i < k; i++) sum += a[i];

    int ans = sum;
    for (int i = k; i < n; i++) {
        sum += a[i] - a[i - k];
        ans = max(ans, sum);
    }

    cout << ans;
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: