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 main() {

	int n, k;
	int a[100000];

	while(cin >> n >> k) {
		if(n==0&&k==0) {
			break;
		}
		for(int i=0; i<n; i++) {
			cin >> a[i];
		}
		int max=a[0];
		for(int i=0; i<=n-k; i++) {
			int t=0;
			int l=0;
			for(int j=i; j<n; j++) {
				l++;
				t+=a[j];
				if(t>max) {
					max=t;
				}
				if(l==k) {
					break;
				}
			}
		}
		cout << max << endl;
	}

	return 0;

}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main(){
  int n, k;
  int N[100001], ans, sum;
  while(cin >> n >> k, n && k){
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }
    for(int i = 0 ; i < n - k ; i++){
      sum = 0;
      for(int j = i ; j < k + i ; j++){
	sum += N[j];
	//if(N[j+k-1] > 10000) break;
      }
      ans = max(ans, sum);
      //cout << ans << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

int main(){
	int n,k,S,max,count;

	while(true){
		scanf("%d %d",&n,&k);
		if(n == 0 && k == 0)break;
		max = -1000000001;
		S = 0;
		count = 0;
		int array[n];
		for(int i = 0; i < n; i++){
			scanf("%d",&array[i]);
			count++;
			if(count == k){
				S += array[i];
				max = (max >= S)?max:S;
			}else if(count >  k){
				S -= array[i-k];
				S += array[i];
				max = (max >= S)?max:S;
			}else{
				S += array[i];
			}
		}
		printf("%d\n",max);
	}

	return 0;
}

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

using namespace std;

int main()
{
	int n, k, s, b;
	while (1)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		int m[100001] = { 0 };
		int a[100001];
		for (int i = 0;i < n;i++)
			cin >> a[i];

		m[0] = 0;
		for (int i = 0;i < n;i++)
			m[i + 1] = m[i] + a[i];

		s = 0;
		for (int i = 0;i < n - k + 1;i++)
		{
			b = m[i + k ] - m[i ];
			if (s < b) 
				s = b;
		}

	}
	cout << s << endl;
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a[100010] = {};
	for (int n, k; cin >> n >> k&&n;) {
		rep(i, 0, n) {
			cin >> a[i];
		}
		int ans = accumulate(a, a + k, 0);
		rep(i, k, n) {
			ans = max(ans, ans + a[i] - a[i - k]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int ans, tmp;

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

        int a[n];
        for(int i=0; i<n; i++) cin >> a[i];
        ans = 0;
        for(int i=0; i<k; i++) ans += a[i];
        tmp = ans;
        for(int i=0; i<n-k; i++) {
            tmp = tmp + a[k + i] - a[i];
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }

    return 0;
}

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

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

last updated: 2013-07-10@16:50

 **********************************************/
#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;
                vector<int> data(5000);

                cin >> n >> k;
                if(n==0 && k==0)break;
                
                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;
  while(cin>>n>>k,n+k!=0){
    long long htoohtoo[n];
    for(int i=0;i<n;i++)
      cin>>htoohtoo[i];
    long long htoo=0;
    long long max=0;
    for(int i=0;i<n-k+1;i++){
      htoo = 0;
      for(int j=0;j<k;j++){
	htoo+=htoohtoo[i+j];
      }
      if(max<htoo){
	max=htoo;
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

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

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

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

int n, k;
int a[100000];
int ra[100001];	//ra[i] = a[0] + ??? + a[i-1]

int main() {
	while (cin >> n >> k) {
		for(int i = 0; i < n; i++) cin >> a[i];
		if (!n) { break; }
		ra[0] = 0;
		for (int i = 0; i < n; i++) {
			ra[i+1] = ra[i] + a[i];
		}

		int ans = -1000000001;
		for (int i = k; i <= n; i++) {
			ans = max(ans, ra[i] - ra[i-k]);
		}

		cout << ans << endl;
	}
	return 0;
}