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 <bits/stdc++.h>
using namespace std;

int64_t	calc_partial_sum(int n, int k, const vector<int> &a_vec)
{
	int64_t	s = 0;
	int64_t	max_s = 0;
	for (int i = 0; i < k; ++i)
		s += a_vec.at(i);
	max_s = s;
	for (int i = k; i < n; ++i) {
		s += a_vec.at(i) - a_vec.at(i - k);
		if (max_s < s)
			max_s = s;
	}
	return max_s;
}

int	main()
{
	int	n, k;
	while (cin >> n >> k) {
		if (n == 0 && k == 0)
			break;
		vector<int>	a_vec(n);
		for (int i = 0; i < n; ++i)
			cin >> a_vec.at(i);
		cout << calc_partial_sum(n, k, a_vec) << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int a[100100];
int main()
{
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++)cin >> a[i];
	int ans=-INF;
	int base=0;
	for(int i=0;i<k;i++)base+=a[i];
	ans=base;
	for(int i=k;i<n;i++)
	{
		base-=a[i-k];
		base+=a[i];
		ans=max(ans,base);
	}
	cout << ans << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    while(1){
        int N,K;
        cin>>N>>K;
        if(N ==  0 && K == 0) break;
        vector<long long> A(N);
        for(int i=0; i<N; i++) cin>>A[i];

        vector<long long> sum(N+1,0);
        for(int i=1; i<=N; i++){
            sum[i] = sum[i-1]+A[i-1];
        }

        long long ans=0;

        for(int i=0; i<=N-K; i++){
            ans = max(ans,sum[i+K]-sum[i]);
        }

        cout<<ans<<endl;
    }

    return 0;
}

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

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

C++: #include<iostream>
using namespace std;
int main(){
	int cnt,n,m,dat[110000];
	while(1){
	cin>>n>>m;
	if(n==0 && m==0){
		break;
	}
	for(int i=0;i<n;i++){
		cin>>dat[i];
	}
	int ans=0;
	for(int i=0;i<m;i++){
		ans+=dat[i];
	}
	cnt=ans;
	for(int i=m;i<n;i++){
		cnt+=dat[i]-dat[m-i];
		if(cnt>ans){
			ans=cnt;
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
long long int n,a[100000001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
return 0;
}

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

using namespace std;

int main()
{
	int n,m,i,j,ss,ans;
	vector<int> num;
	
	for(;;)
	{
		cin >> n >> m ;
		
		if(n==0 && m==0)
			break;
		
		num.clear();
		ss=0;
		
		for(i=0;i<n;i++)
		{
			int a;
			cin >> a ;
			num.push_back(a);
		}
		
		for(i=0;i<m;i++)
		{
			ss+=num[i];
		}
		
		ans=ss;
		m--;
		
		for(i=1;i<n-m;i++)
		{
			ss-=num[i-1];
			ss+=num[i+m];
			if(ans<ss)
			{
				ans=ss;
			}
		}
		
		cout << ans << endl;
	}
}

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

int main(){

  int n,k,i,j;

  while(1){

  int a[1000003]={0};
  int max=0,sum[1000003]={0};

    scanf("%d %d",&n,&k);

    if(n==0 && k==0){
      break;
    }

    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    for(i=0;i<n;i++){
      if(i+k<=n){
      for(j=i;j<i+k;j++){
	sum[i]+=a[j];
      }
      }
      if(max<sum[i]){
	max=sum[i];
      }
      }
  
    printf("%d\n",max);

  }

  return 0;

}

C++: #include <cstdio>
#include <vector>
using namespace std;
#define MAX_N 100000

int main(){
	int n, k;
	while( scanf("%d %d", &n, &k), n | k ){
		vector<int> data(MAX_N);
		for( int i=0; i<n; i++ ){
			scanf("%d", &data[i]);
		}
		int ans = 0;
		for( int i=0; i<=n-k; i++ ){
			int sum = 0;
			for( int j=0; j<k; j++ ) sum += data[i+j];
			ans = max(ans, sum);
		}
		printf("%d\n", ans);
	}
}

C++: /**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@17:04

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){
                
                int n=0;
                int k=0;
                int total=0, answer=0;
               

                cin >> n >> k;
                if(n==0 && k==0)break;
                vector <int> data(n);
                
                for(int i=0; i<n; i++){
                        cin >> data[i];
                        //cout << "data[i]="<< data[i]<<endl;
                }

                for(int j=0; j<n-k+1; j++){
                        
                        if( j == 0){
                                for(int i=0; i<k; i++){
                                        total = total + data[j+i];
                                }
                                //cout << "subtotal1="<<total<<endl;
                        }else{
                                
                                total = total - data[j-1] + data[j+k-1];
                                //cout << "subtotal2="<<total<<endl;
                        }
                        //cout << "answer="<<answer<<"subtotal="<<total<<endl;
                        if( total > answer ){
                                answer = total;
                        }
                        //cout << "answer="<<answer<<endl;
                }
                
                cout << answer << endl;
                
        }

        return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
  int n,k,sn;
  int s,h,ans;
  while(cin>>n>>k){
    if(n==0&&k==0) break;
    int a[k];
    ans = -1000000;
    for(int i=0;i<k;i++) a[i] = -10000000;
    for(int i=0;i<n;i++){
      cin >> sn;
      h = 0;
      s = 0;
      while(h!=k){
	if(h==k-1){
	  a[h] = sn;
	}
	else  a[h] = a[h+1];
	s += a[h];
	h++;
      }
	if(ans<s) ans = s;
    }
    cout << ans << endl;
  }
  return 0;
}