KSUM


Submit solution

Points: 100
Time limit: 1.0s
Memory limit: 493M

Problem type

Comments


  • 0
    Lop8_voanhkhoa  commented on Feb. 17, 2025, 8:07 a.m.

    include <bits/stdc++.h>

    define ll long long

    define fr(i,a,b) for(int i=a; i<=b; i++)

    using namespace std; const int N = 1e5+5; int n, k, w[N]; ll s[N]; int main() { cin >> n >> k; fr(i,1,n) cin >> w[i]; s[0] = 0; fr(i,1,n) s[i] = s[i-1] + w[i]; ll res = -1e15; fr(i, 1, n-k+1) res = max(res, s[i+k-1] - s[i-1]); cout<< res; return 0; }