Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
573 B
2
Indexable
#include <iostream>
#include <climits>

using namespace std;

typedef long long ll;

ll max(ll a, ll b){
    if(a > b) return a;
    return b;
}

ll a[1000001];

int main(){
    freopen(".inp", "r", stdin);
    freopen(".out", "w", stdout);

    int n, k, tmp; a[0] = 0;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> tmp;
        a[i] = a[i-1] + tmp;
    }

    n = n - k; ll l, r, ma = LLONG_MIN;

    for(int i = k; i <= n; i++){
        l = a[i] - a[i-k];
        r = a[i+k] - a[i];
        ma = max(ma, l-r);
    }
    cout << ma;

    return 0;
}
Leave a Comment