Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 998244353;


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> a(N);
    vector<int> wa(N+1);
    wa.at(0) = 0;
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
        wa.at(i+1) = a.at(i) + wa.at(i);
    }
    int ANS = -INF;
    for(int i = 0; i < N - K +1; i++){
        int ans = wa.at(i+K) - wa.at(i);
        ANS = max(ANS, ans);
    }
    cout << ANS << endl;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int main(void)
{
int n,k,s,b;
while(1)
{
cin >> n >>k;
if(n==0 && k==0)
break;
int m[100001]={0};
int a[100001];

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

m[0]=0;
for(int i=0;i<n;i++)
m[i+1]=m[i]+a[i];

s=0;

for(int i=1;i+k<=n;i++)
{
b=m[i+k]-m[i];
if(s<b)
s=b;
}
}
cout << s << endl;
return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int n,k,s,data;
	s = 0;
	
	while(cin >> n >> k, n && k){
	vector<int> sum;	

	rep(i,n){
		cin >> data;
		sum.push_back(data);
	}
	
	data = 0;

	rep(i,k){

		data += sum[i];
		
	}

	int res;
	res = data;
	
	rep(i,n - k){
		data -= sum[i];
		data += sum[i+k];
		res = max(res,data);
	}

	cout << res << endl;
	}
	
	return 0;
}

C++: #include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;

ll sum[100010];
ll a[100010];

int main()
{
	while (1) {
		ll n, k;
		if (n == 0 && k == 0)break;
		cin >> n >> k;

		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}

		sum[1] = a[1];
		for (int i = 2; i <= n; i++) {
			sum[i] = sum[i - 1] + a[i];
		}

		ll mx = 0;
		ll ans = 0;
		for (int i = k; i <= n; i++) {
			mx = sum[i] - sum[i - k];
			ans = max(mx, ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int num[100100];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<100001;i++){
              num[i]=0;
              if(num[i+1]==0)break;
         }
         cin>>n>>m;
         if(n==0&&m==0)break;
         for(int i=0;i<n;i++) cin>>num[i];
         for(int i=0;i<n-m;i++){
              int min=0;
              for(int j=i;j<i+m;j++)min+=num[j];
              if(ans<min)ans=min;
         }
         cout<<ans<<endl;
         ans=0;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;



int main(){
        int n, k,max,temp,num,total;
        while(true) {  //ベクターに格納
                cin >> n>>k;
                if(n==k!=0){
                  break;
                }
                vector<double> v;
                total=0;
                v.push_back(total);
                for(int i=0;i<n;i++){
                  cin>>num; //入力をnumに代入
                  total+=num;
                  v.push_back(total); //ベクターvにプッシュ
                }

                max=0;
                temp=0;
                for(int i=0; i+k<=n; i++) {
                        temp=v[i+k]-v[i];
                        if(temp>max) max=temp; //tempが最も大きい数値ならmaxを更新
                        temp=0; //tempの初帰化
                }
                cout<<max<<endl;
        }
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, k;
    while (cin >> n >> k)
    {
        if (n == 0 && k == 0)
        {
            break;
        }
        vector<int> s(n);
        rep(i, n) cin >> s[i];

        vector<ll> cum(n + 1, 0);
        rep(i, n)
        {
            cum[i + 1] += cum[i] + s[i];
        }
        ll ans = 0;
        rep(i, n + 1 - k)
        {
            ans = max(ans, cum[k + i] - cum[i]);
        }
        cout << ans << endl;
    }

    return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
    while(1){
        int num[100000] = {0};
        int sum = 0;
        int ma = -100000;
        int n,k;
        scanf("%d%d",&n,&k);
        if(n == 0 && k == 0) break;

        for(int i = 0;i < n;i++){
            scanf("%d",&num[i]);
            if(i < k) sum += num[i];
        }
        ma = max(sum,ma);
        for(int i = 0;i < n-k;i++){
            sum += num[k+i] -num[i];
            ma = max(sum,ma);
        }
        printf("%d\n",ma);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main(){
	int n, k;
	vector< int > a;
	vector< int > r;
	
	while(cin >> n >> k, n){
		a.CLR();
		r.CLR();
		
		a.RS(n);
		r.RS(n - k + 1);
		
		REP(i, n) cin >> a[i];
		
		REP(i, k) r[0] +=  a[i];
		
		FOR(i, k, n){
			r[i-k+1] = r[i-k] + a[i] - a[i-k];
		}
		
		REP(i, n - k + 1){
			cout << r[i] << endl;
		}
		
		//cout << *max_element(ALL(r)) << endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i==n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        int x=S[k];
        for(int l=1;l==n-k;l++){
            if(x<S[k+l]-S[l]){
                x==S[k+l]-S[l];
            }
        }
            cout << x << endl;;
            cin >> n >> k;
        }

    }

}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    vector<ll> ans;
    while (true){
        int n,k;cin>>n>>k;
        if (n==0 && k==0){
            break;
        }
        vector<ll> a(n);
        rep(i,0,n) cin>>a[i];
        vector<ll> b(n+1,0);
        rep(i,0,n) b[i+1] = b[i] + a[i];
        ll num = 0;
        rep(i,0,n-k){
            num = max(num,b[i+k]-b[i]);
        }
        ans.push_back(num);
    }
    for(auto x:ans){
        cout<<x<<endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int a[100000];
int main(){
	int n,k,best;
	while(true){
	cin>>n>>k;
	if(n==0&&k==0)
		break;
	best=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<k;i++)
		best+=a[i];
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k])
			best=best+a[i]-a[i-k];
	}
	cout<<best<<endl;
	}
    return 0;
}