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 <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;
#define sq(x) ((x)*(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int n, k;
	while(cin >> n >> k, n|k){
		queue<int> q;
		int sum = 0;
		int ans = -1e10;
		rep(i, n){
			int a;
			cin >> a;
			sum += a;
			q.push(a);
			if(q.size() >= k){
				ans = max(ans, sum);
				sum -= q.front();
				q.pop();
			}
		}
		cout << ans << endl;
	}
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
ll bit[100010];
int n;
int k;
ll sum(int i){
	ll s = 0;
	while(i > 0){
		s +=bit[i];
		i -=i&-i;
	}
	return s;
}

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

int main(){
	while(cin>>n>>k,n||k){
		memset(bit,0,sizeof(bit));
		for(int i = 0;i < n;i++){
			int num;
			cin>>num;
			add(i+1,num);
		}
		ll res =numeric_limits<ll>::min();
		for(int i = 1;i+k-1<=n;i++){
			res =max(sum(i+k-1)-sum(i-1),res);
		}
		cout <<res<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define N 100000
using namespace std;
int main(){
  int n,k,in[N],maxv,sum,i;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    maxv=-200000;
    sum=0;
    for(i=0;i<n;i++){
      cin >> in[i];
      sum+=in[i];
      if(i>=k-1) sum-=in[i-k];
      maxv=max(maxv,sum);
    }
    cout << maxv << endl;
  }
  return 0;
}

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

int main(){
    int n,a[100001]={0},k,sum,p;
int i,j,h;
cin>>n>>k;
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
sum=a[k];
for(i=k+1;i<=n;i++){
    sum=max(sum,a[i]-a[i-k]);
		}
cout<<sum<<endl;
return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int a[MAX_N];

int main()
{
	int n,k;
	while(scanf("%d%d",&n,&k)>0){
		rep(i,n){
			scanf("%d",&a[i]);
		}
		ll ans=0;
		ll s=0;
		int id=0;
		while(id<n){
			s += a[id];
			if(id>=k){
				s-=a[id-k];
				ans = max(ans,s);
			}else if(id==k-1){
				ans = s;
			}
			id++;
		}
		cout << ans << "\n";
		scanf("%d%d",&n,&k);
	}
	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,ans2;
	int num[100001];
	int n,k;
	int a;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0 && k==0)break;
		ans=0;
		for(a=0;a<n;a++)scanf("%d",&num[a]);
		for(a=0;a<k;a++){
			ans+=num[a];
		}
		ans2=ans;
		for(a=k;a<n;a++){
			ans2+=num[a]-num[a-k];
			ans=max(ans,ans2);
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int n,k;
    while (cin >> n >> k) 
    {
        if (n == 0 && k==0) 
        {
            break;
        }
        vector<int> vec(n);
        int sum_max=0;
        int j;
        int sum=0;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];

            if (k  == i + 1) 
            {
                for (j = 0; j < k; j++) 
                {
                    sum += vec[i - j];
                }
                sum_max = max(sum ,sum_max);
                sum -= vec[i-k+1];
            }
            else if (k  < i + 1) 
            {
                sum += vec[i];
                sum_max = max(sum ,sum_max);
                sum -= vec[i-k+1];
            }
        }
        cout << sum_max << endl;
    }
    return 0;
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0)break;
    outp.resize(a+1,0);
    vector<int> num(numn);
    for(int n = 0;n<serchn - 1;n++){
      cin >> num[n];
      gh += num[n];
    }
    for(int n = 0;n<numn - serchn + 1;n++){
      cin >> num[n+2];
      gh += num[n+2];
      if(gh > outp[a])outp[a] = gh;
      gh = gh - num[n];
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  return 0;
}

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


int main()
{
while(true) {
int n, k;
vector<int> x;
scanf("%d%d", &n, &k);
if(n == 0)
break;
x.resize(n);
for(int i = 0; i < n; ++i)
scanf("%d", &x[i]);
int cur = 0, ans;
for(int i = 0; i < k; ++i)
cur += x[i];
ans = cur;
for(int i = k; i < n; ++i) {
cur += x[i];
cur -= x[i - k];
ans = max(ans, cur);
}
printf("%d\n", ans);
}
return 0;
}

C++: #include<cstdio>
using namespace std;
int main(){
    int n,k;
    int s = 0;
    int a[10000] = {0};
    for(;;){
        scanf("%d%d",&n,&k);
        if(n == 0&&k == 0)break;
        for(int i = 0;i < n; i++){
            scanf("%d",&a[i]);
        }
        int x = 0;
        for(int i = 0;i < (n-k+1); i++){
            for(int j = i;j < (k+i); j++){
                s += a[j];
            }
            if(x < s)x = s;
            s = 0;
        }
        printf("%d\n",x);
    }
    return 0;
}