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<iostream>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
	int n,k;
	queue<int> q;
	while(cin>>n>>k,n||k){
		while(!q.empty())q.pop();
		int t,sum=0,ans= -10000*100000;
		for(int i=0;i<k;i++){
			cin>>t;
			sum += t;
			q.push(t);
		}
		ans=max(ans,sum);
		for(int i=0;i<n-k;i++){
			t=q.front();
			q.pop();
			sum -= t;
			cin>>t;
			sum += t;
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

constexpr int MAX_N= 100000;

int n,k;
int sums[MAX_N];

int main(){
	std::cin>>n>>k;
	for(int i=0;i<n;++i)
		std::cin>>sums[i];

	for(int i=1;i<n;++i)
		sums[i]+=sums[i-1];

	int ans=sums[k-1];

	for(int i=0;i<n-k+1;++i){
		ans=std::max(ans,sums[i+k]-sums[i]);
    }
	std::cout<<ans<<std::endl;

	return 0;
}

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

#define INT_MIN -2147483648
#define MAX_N 100010
int N, K;
int S[MAX_N];

int main() {
  while (true) {
  cin >> N >> K;
  if (N == 0 && K == 0) break;
  int ans = INT_MIN;
  for (int i=0; i<N; i++) cin >> S[i];

  for (int i=0; i<=N-K; i++) {
    int t = 0;
    for (int j=0; j<K; j++) t += S[i+j];
    ans = max(ans, t);
  }
  cout << ans << "\n";
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

#define NMAX 5000

int n, k;
int a[NMAX];

int solve() {
    int max_sum = -10000000;
    int sum = 0;
    for (int i = 0; i + k < n; i++) {
        for (int j = i; j < i + k; j++) {
            sum += a[j];
        }
        if (sum > max_sum) max_sum = sum;
        sum = 0;
    }
    return max_sum;
}

int main() {
    while (true) {
        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) break;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        printf("%d\n", solve());
    }
    return 0;
}

C++: #include<iostream>
#include<stdio.h>

using namespace std;


int main(){

while(1){
    int n, k;
    cin>> n>> k;
    if(n==0&&k==0) break;
    int a[n];
    for(int i=0; i<n; i++){
        cin>> a[i];
    }
    int s[n+1];
    fill(s, s+n+1, 0);
    for(int i=0; i<n; i++){
        s[i+1]=s[i]+a[i];
    }
    int ans=-100100100;
    for(int i=k; i<=n; i++){
        ans=max(ans, s[i]-s[i-k]);
    }

    cout<< ans<< endl;
}
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long long int INF =  1LL<<60; 
int main() {
    while(true) {
        int N, K;
        cin >> N >> K;
        if(N == 0 && K == 0) {
            break;
        }
        vector<int> a(N);
        for(int i = 0; i < N; i++) {
            cin >> a[i];
        }
        int max = 0;
        vector<int> s(N+1);
        for(int i = 0; i < N; i++) {
            s[i+1] = s[i] + a[i];
        }
        long long int res = -INF;
        for(int i = 0; i+K <= N; i++) {
            long long int value = s[i+K] - s[i];
            if(res < value) {
                res = value;
            }
        }
            cout << res << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n, k;
		double a[100001] = {}, b[100001] = {}, ans;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		else{
			cout << ans << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int n,k;
int main(){
	while(cin>>n>>k){
	int ans=0;
	if(n==0 && k==0){
		break;
	}
	int a[n+2];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-3;i++){
		int cnt=0;
		for(int j=0;j<k;j++){
		cnt=cnt+a[i+j];
		}
		ans=max(cnt,ans);
	}
	cout<<ans<<endl;
	}

	return 0;
	

}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < 3){
    	    total = total + a[i];
    	}else{
    	    total = total + a[i] - a[i-3];
    	}
	    if(ans < total){
	        ans = total;
	    }
    }
    cout << ans << endl;
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa )
{
	int temp = 0;
	int i;
	/*
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	*/
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0));
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	while(true){
	int n , k ,ans;
	double a[100001] = {}, b[100001] = {};
	cin >> n >> k;
	if (n==0||k==0)	break;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n-k+1; i ++){
		b[i] = a[i] + a[i + 1] + a[i + 2];
		if (b[i]>b[i - 1]){
				ans = b[i];
		}
	}
	cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  while(true){
    int a[100000] = {0};
    int n, k;
    cin >> n >> k;
    if(!n)
      break;
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int aa = 0;
    for(int i = 0; i < k; i++){
      aa += a[i];
    }
    //cout << "f:" << aa << endl;
    for(int i = k; i < n; i++){
      int aaa = aa - a[i - k] + a[i];
      aa = aaa > aa ? aaa : aa;
      //cout << "f:" << aa << " n:" << aaa << endl;
    }
    cout << aa << endl;
  }
  return 0;
}

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

int main()
{
	int n,k;

	int suu[100000 + 100] = { 0 };
	int a;
	int i;
	int mx;

	cin >> n >> k;

	while (n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{

			cin >> a;

			suu[i] = a + suu[i - 1];

			if (i >= k)
			{
				if (mx < suu[i] - suu[i - k])
				{
					mx = suu[i] - suu[i - k];
				}

			}

		}

		/*
		for (i = k; i <= n; i++)
		{
			if (mx < suu[i] - suu[i - k])
			{
				mx = suu[i] - suu[i - k];
			}

		}
		*/

		cout << mx << endl;


		cin >> n >> k;
		mx = 0;
	}
	return 0;
}

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

int main(){
	int n, k, a[100000] = {};
	long long int sum = -10000000, tmp;
	while(cin >> n >> k){
		if(n == 0 && k == 0) break;
		for(int i = 0;i<n;i++){
			cin >> a[i];
		}
		for(int i = 0;i + k<n;i++){
			tmp = 0;
			for(int j = 0;j<k;j++){
				tmp += a[i + j];
			}
			if(sum < tmp) sum = tmp;
		}
		cout << sum << endl;
	}
	return 0;
}