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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n,k;cin>>n>>k,n|k;){
		vi a(n);
		rep(i,n)
			cin>>a[i];
		
		int sum=accumulate(a.begin(),a.begin()+k,0);
		int res=sum;
		repi(i,k,n){
			sum=sum+a[i]-a[i-k];
			res=max(res,sum);
		}
		cout<<res<<endl;
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

LL S[MAX_N+1],n,m;
LL ans;

class BIT{
    public:
        int N;
        void init(int _N){
            N=_N;
            rep(i,N+1)S[i]=0;
        }

        LL getSum(int i){
            LL s=0;
            while(i){
                s+=S[i];
                i-=i&-i;
            }
            return s;
        }

        void add(int i,int x){
            while(i<=N){
                S[i]+=x;
                i+=i&-i;
            }
        }
};

int main(){
    while(1){
        BIT bit;
        int t=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        bit.init(n);
        FOR(i,1,n){
            int x;
            cin>>x;
            bit.add(i,x);
        }
        FOR(i,m,n){
            LL query=bit.getSum(i)-bit.getSum(t);
            ans=max(query,ans);
            t++;
        }
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	while (1) {
		int n, k, a[100005] = { 0 }, sum[100005] = { 0 };
		long long m = -9999999999;
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < k; i++) {
			sum[0] += a[i];
		}
		for (int i = 1; i < n - 2; i++) {
			sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
		}
		for (int i = 0; i < n - 2; i++) {
			if (m < sum[i]) {
				m = sum[i];
			}
		}
		cout << m << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
    int a[100010],n,k;
    while(cin>>n>>k,n||k){
        for(int i=0;i<n;i++)cin>>a[i];
        int mx=-1;
        int sum=0;
        for(int i=0;i<k;i++)sum+=a[i];
        mx=sum;
        for(int i=k;i<n;i++){
            sum-=a[i-k];
            sum+=a[i];
            mx=max(mx,sum);
        }
        cout<<mx<<endl;
    }
}

C++: #include<stdio.h>

//更新書き換え型
int MAX(int *num,int n,int k){
	int i,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	now = max;
	for(i = 0;i < n-k;i++){
		now += num[i+k]-num[i];
		if(max < now)
			max = now;
	}
	return max;
}
int main(){
	int n,k,max;
	int *num;
	int i;
	while(1){
		scanf("%d%d",&n,&k);
		if(n == 0 && k == 0)
			break;
		num = new int[n];
		for(i = 0;i < n;i++){
			scanf("%d",num+i);
		}
		max = MAX(num,n,k);
		printf("%d\n",max);
		delete[] num;
	}
	return 0;
}

C++: #include<iostream>

const int MAX_N = 1 << 17, INF = 1 << 24;
class BIT{
public:
	BIT(int _n)
		:n(_n){
		std::fill(bit, bit+n, 0);
	}
	int sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	int add(int i, int x){
		while(i <= n){
			bit[i] += x;
			i += i & -i;
		}
	}
private:
	int bit[MAX_N], n;
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		BIT b(n+1);
		for(int i=1;i<=n;i++){
			int a_i;
			std::cin >> a_i;
			b.add(i, a_i);
		}

		int res = -INF;
		for(int i=1;i+k-1<=n;i++){
			res = std::max(res, b.sum(i+k-1) - b.sum(i-1));
		}

		std::cout << res << std::endl;
	}
}

C++: # include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int n, k;
	while (cin >> n >> k) {
		vector<int> num;
		if (n == 0 && k == 0) {
			break;
		}
		int o;
		for (int i = 0; i < n; i++) {
			cin >> o;
			num.emplace_back(o);
		}
		int m = 0;
		for (int i = 0; i < n - k + 1; i++) {
			int h = 0;
			for (int j = 0; j < k; j++) {
				h += num[i + j];
			}
			m = max(m, h);
		}
		cout << m << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int n, k, a[200000], s, ret;
int main() {
	while (true) {
		cin >> n >> k; if (n == 0)break; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (i <= k)s += a[i]; }
		ret = s; for (int i = k + 1; i <= n; i++) { s -= a[i - k]; s += a[i]; ret = max(ret, s); }
		cout << ret << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	long long int ans;
	long long int kans;
	int num[100001];
	int n,k;
	int a,b;
	ans=0;
	scanf("%d%d",&n,&k);
	for(a=0;a<n;a++)scanf("%d",&num[a]);
	for(a=0;a<n-k;a++){
		kans=0;
		for(b=0;b<k;b++){
			kans+=num[a+b];
		}
		ans=max(ans,kans);
	}
	printf("%d\n",ans);
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <climits>
int main()
{
	int n,k;
	while(std::cin>>n>>k,n|k){
		int memo[100000];
		int ans = INT_MIN;
		int cnt = 0;
		int sum = 0;
		memset(memo,0,sizeof(memo));
		
		for(int i=0; i<n; i++){
			int a; std::cin>>memo[i];
			if(cnt<k){
				sum+=memo[i]; cnt++;
			}
			else{
				sum = sum-memo[i-k]+memo[i];
				//printf("sum:%d\n",sum);
			}
			if( k==cnt && sum>ans ) ans = sum;
			//printf("sum:%d\n",sum);
		}
		printf("%d\n",ans);
	}
	return 0;
}