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 <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int n, k;
  while(cin >> n >> k, n || k){
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i++) cin >> arr[i];
    int sum = 0, ans = 0;
    for(int i = 0; i < k; i++) sum += arr[i];
    ans = sum;
    for(int i = 1; i + k - 1 < n; i++){
      sum -= arr[i-1];
      sum += arr[i+k-1];
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main(){

	int n,k,a[100000],sum,ans;

	while(cin>>n>>k,n||k){

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

	sum=0;

    for(int i=0;i<k;i++){
    	sum=sum+a[i];
    }

    ans=sum;

    for(int i=0;i<k;i++){
    	if(n==(k+i)){
    		break;
    	}
    	sum=sum-a[i]+a[k+i];
    	ans=max(ans,sum);
    }

    cout<<ans<<endl;


	}
}

C++: // Cumulative sum
#include <algorithm>
#include <cstdio>
using namespace std;

int sum[100010];
int main(void)
{
    int n, k;
    while(1) {
        scanf("%d %d", &n, &k);
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        for(int i=0; i<n; i++) sum[i+1] = sum[i] + a[i]; // sum[i] := a[0]??????a[i-1]?????§??????(sum[0]=0)

        int ans = -114514810;
        for(int i=0; i<n-k+1; i++)
            ans = max(ans, sum[i+1+k] - sum[i+1]);
        printf("%d\n", ans);
    }

    return 0;
}

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

using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main()
{
    long long n,k;
    long long temp;
    long long ans;
    vector<long long> num;

    cin >> n >> k;
    while(n!=0 && k!=0) {
        for(long long i=0; i<n; ++i) {
            cin >> temp;
            num.push_back(temp);
        }


        ans=0;

        for(long long i=0; i<k; ++i) {
            ans+=num[i];
        }

        if(k!=n) {
            for(long long i=k; i<n; ++i) {
                ans=MAX(ans,ans+num[i]-num[i-k]);
            }
        }

        cout << ans << endl;
        num.clear();
        cin >> n >> k;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int num[1001000];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<1001000;i++)num[i]=0;
         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=num[i]+num[i+1]+num[i+2];
              if(ans<min)ans=min;
         }
         cout<<ans<<endl;
         ans=0;
    }
    return 0;
}

C++: // 2011/09/27 Tazoe

#include <iostream>
using namespace std;

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

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

		int sum = 0;
		for(int i=0; i<k; i++)
			sum += a[i];

		int max = sum;
		for(int i=k; i<n; i++){
			sum += a[i];
			sum -= a[i-k];
			if(max<sum)
				max = sum;
		}

		cout << max << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int a[100001];
int main(void)
{
	int n,k,sum,max=0,i,j;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0) break;
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		for(i=1;i<=n;i++){
			sum=0;
			if(i+k<=n){
				for(j=i;j<i+k;j++){
					sum+=a[j];
				}
				if(max<sum){
					max=sum;
				}
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define INF 1000000
using namespace std;


main() {
  while(1) {
    int n, k;
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    int buf[k];
    fill_n(buf, k, 0);
    int maxS = -INF;
    int sum = 0;
    for(int i = 0; i < n; i++) {
      sum -= buf[0];
      for(int j = 0; j+1 < k; j++) buf[j] = buf[j+1];
      cin >> buf[k-1];
      sum += buf[k-1];
      if(i+1 < k) continue;
      if(maxS == -INF || sum > maxS) maxS = sum;
    }
    cout << maxS << endl;
  }
}

C++: #include <cstdio>

using namespace std;

int n=1,k=1,s,smax;
int a[100000];
int s1,s2;

int main(){
	while(1){
	scanf("%d %d\n",&n,&k);
	if(n==0&&k==0) break;
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
	printf("%d\n",smax);
	}
	return 0;
}

C++: #include<cstdio>

int main()
{
    int n,m,a[100008];
    while(~scanf("%d%d",&n,&m))
    {
        if(!n&&!m) break;
        int temp = 0;
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        for(int i=0;i<m;i++) temp += a[i];
        int sum = 0,cap = 0;
        for(int i=0;i<n;i++){
            if(cap!=m){ sum += a[i]; cap++; }
            else sum += a[i]-a[i-3];
            if(sum>temp) temp=sum;
        }
        printf("%d\n",temp);
    }
    return 0;
}

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

using namespace std;

int n,m;
int x,s;
int a[100000];

int main(void){

  while( cin >> n >> m , n || m ){

    for( int i = 0 ; i < n ; i++ ){
      cin >> a[i];
    }
    x = 0;
    for( int i = 0 ; i < m ; i++ ){
      x += a[i];
    }
    s = x;
    for( int i = 0 ; i < n - m ; i++ ){
      x -= a[i];
      x += a[i + m];
      if( s < x ) s = x;
    }

    cout << s << endl;

  }
  return 0;
}

C++: #include<string>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int main()
{
	int n, k, num, ans, sam;
	
	while(cin >> n >> k)
	{
		queue<int> que;
		ans = 0;
		sam = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> num;
			que.push(num);
			sam += num;
			if(que.size() == 3 )
			{
				if(ans < sam)
				{
					ans = sam;
				}
				sam -= que.front();
				que.pop();
			}
		}
		cout << ans << endl;
	}
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long m[100000][2];
int main(){
while(1){
long long n,k,i,j,x=0;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=0;i<n;i++)cin>>m[i][0];
m[0][1]=m[0][0];
for(i=1;i<n;i++){
m[i][1]=m[i-1][1]+m[i][0];
}
x=m[k-1][1];
for(i=k;i<n;i++){
x=max(x,m[i][1]-m[i-k][1]);
}
cout<<x<<endl;
}
return 0;
}