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>
using namespace std;

int seq[100000];
int n,k;

int req(int rem, int i)
{
	rem -= seq[i];
	rem += seq[i+k];
	return rem;
}
int main()
{
	while(cin >> n >> k){
		if(n==0&&k==0)
			break;
		for(int i=0;i<n;i++){
			cin >> seq[i];
		}
		int rem=0;
		for(int i=0;i<k;i++){
			rem+=seq[i];
		}
		for(int i=0;i<n-k;i++){
			rem = max(rem,req(rem,i));
		}
		cout << rem << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, k;
    while(cin>>n>>k, n){
        vector<int> a(n);
        for(int i=0; i<n; i++) cin>>a[i];

        vector<ll> sum(n+10, 0);
        for(int i=1; i<=n; i++) sum[i]=sum[i-1]+a[i-1];

        ll ans=-INF;
        for(int i=1; i+k-1<=n; i++){
            chmax(ans, sum[i+k-1]-sum[i-1]);
        }
        cout << ans << endl;
    }
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int main() {
	int n, k;
	while (scanf("%d %d",&n,&k)&&n!=0) {
		vector<int> a(n);
		for (int i=0; i<n; i++) scanf("%d",&a[i]);
		int max=0;
		for (int i=0; i<k; i++) max+=a[i];
		int tmp=max;
		for (int i=0; i<n-k; i++) {
			tmp=tmp-a[i]+a[i+k];
			if (tmp>max) max=tmp;
		}
		printf("%d\n",max);
	}
}

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

int num[100000];
int main(){
    int n, k;
    int a;
    int i;
    long long int now;
    long long int max;
    cin >> n >> k;
    while(n || k){
        for(i=0;i<n-k;i++){
            num[i] = 0;
        }
        now = 0;
        max = 0;
        for(i=0;i<k;i++){
            cin >> a;
            num[i] -= a;
            now += a;
        }
        for(;i<n-k;i++){
            cin >> a;
            num[i] -= a;
            num[i-k] += a;
        }
        for(;i<n;i++){
            cin >> a;
            num[i-k] += a;
        }
        for(i=0;i<n-k+1;i++){
            if(max < now){
                max = now;
            }
            now += num[i];
        }
        cout << endl;
        cout << max << endl;
        cin >> n >> k;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n=0, k=0;
		double a[100001] = {}, b[100001] = {}, ans=0;
		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>
#include<algorithm>
using namespace std;

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

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

		int s[10000] = {};
		for (int i = 0;i < n - k;i++) {
			for (int j = 0;j < k;j++) {
				s[i] += a[i + j];
			}
		}
		sort(s, s + n - k + 1);
		cout << s[n - k] << endl;
	}
	return 0;
}

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

int main()
{
	int n,k,a[100000],temp;
	while(cin >> n >> k,n || k){
		cin >> a[0];
		for(int i = 1;i < n;i++){
			cin >> temp;
			a[i] = a[i - 1] + temp;
		}
		temp = 0;
		for(int i = 0;i < n - k;i++)
			if(temp < a[i + k] - a[i])
				temp = a[i + k] - a[i];
		cout << temp << endl;
	}
	return 0;
}

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

int main(){
int n,k,s,ans;
int a[100001];
while(cin>>n>>k){
if(n==0&&k==0)break;
for(int i=0;i<n;i++)cin>>a[i];
s=0;
for(int i=0;i<n-k+1;i++){
if(i==0)for(int j=i;j<i+k;j++)s+=a[j];
if(i!=0){s-=a[i-1]; s+=a[i+k-1];}
if(i==0)ans=s;
if(s>ans)ans=s;}
cout<<ans<<endl;}}