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++: /**********************************************

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

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

 **********************************************/
#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 all=0;
                int total=0, answer=0;
                vector<int> data(5000);

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

                for(int j=0; j<n-k; j++){
                        
                        for(int i=0; i<k; i++){
                                total = total + data[j+i];
                        }
                        if( answer < total){
                                answer = total;
                        }
                        total = 0;
                }

                cout << answer << endl;
                
        }

        return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int ans=0,n,k,box[10000]={0},sum=0;;
        cin >> n >> k;
        if(n==0&&k==0)break;
        for(int i=0;i<k;i++){
            cin >> box[i];
            sum+=box[i];
            }
            ans=sum;
          for(int i=k;i<n;i++){
                cin >> box[i];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,k;
  while(cin>>n>>k,n+k){
    vector<ll>sum(n);
    ll ans=-llINF;
    for(int i=0;i<k-1;i++){
      cin>>sum[i];
    }
    for(int i=k-1;i<n;i++){
      cin>>sum[i];
      ll mi=0;
      for(int j=0;j<k;j++){
	mi+=sum[i-j];
      }
      //cout<<mi<<endl;
	ans=max(mi,ans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

ll N,K;
ll a[100005];

int main(){
  while(scanf("%lld%lld", &N,&K) && N||K){
    for(int i=0;i<N;i++) scanf("%lld", &a[i]);
    ll sum = 0, res;
    for(ll i=0;i<K;i++) sum += a[i];
    res = sum;
    for(ll i=K;i<N;i++){
      sum -= a[i-K];
      sum += a[i];
      res = max(res, sum);
    }
    printf("%lld\n", res);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,k,res=-1;
  while(cin>>n>>k,n+k){
    vector<int> ary(n);
    int sum = 0;
    rep(i,n){
      cin>>ary[i];
      sum += ary[i];
      if(i >= k){
	sum -= ary[i-k];
      }
      res = max(res,sum);
    }
    cout<<res<<endl;
  }
}

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

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i < n - k + 2; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

// f : 二項演算 Group * Group -> Group
// g : 逆元関数 Group -> Group
// G1 : 単位元
template<typename Group>
class CumulativeSum {
	std::vector<Group> elements;
	std::vector<Group> sum;
	
	bool built;
	
	using F = std::function<Group(Group, Group)>;
	using G = std::function<Group(Group)>;
	
	const F f;
	const G g;
	const Group G1;
	
	private:
	void build() {
		if(built) return;
		built = true;
		sum.assign(elements.size() + 1, G1);
		for(int i = 0; i < elements.size(); i++) sum[i + 1] = f(sum[i], elements[i]);
	}
	public:
	CumulativeSum(F f, G g, Group G1) : f(f), g(g), G1(G1) {
		built = false;
		elements.clear();
		sum.clear();
	}
	CumulativeSum(F f, G g, Group G1, std::vector<Group> vec) : f(f), g(g), G1(G1) {
		built = false;
		elements.swap(vec);
		sum.clear();
	}
	void swap(std::vector<Group> vec) {
		built = false;
		elements.swap(vec);
	}
	void add(Group x) {
		built = false;
		elements.push_back(x);
	}
	void pop_back() {
		if(!elements.size()) return;
		built = false;
		elements.pop_back();
	}
	Group get(int k) { // [0, k)
		build();
		return sum[k];
	}
	Group get(int a, int b) { // [a, b)
		build();
		return f(g(sum[a - 1]), sum[b]);
	}
	int size() {
		return elements.size();
	}
};

int main() {
	int n, k;
	while(scanf("%d%d", &n, &k) and (n and k)) {
		std::vector<i64> a(n);
		for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
		CumulativeSum<i64> cs([](i64 a, i64 b) { return a + b; }, [](i64 a) { return -a; }, 0, a);
		
		i64 ma = -(1LL << 60);
		for(int i = 1; i + k - 1 <= n; i++) ma = std::max(ma, cs.get(i, i + k - 1));
		printf("%lld\n", ma);
	}
	return 0;
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){for(i=s=0;i<n;i++<k&&(M=s+=a[i-1]))std::cin>>a[i];for(i=k;i<n;M<s&&(M=s))s+=a[i]-a[i++-k];}}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n = 0, k = 0;
int a[100001] = {}, b[100001] = {};
int ans;
int main(){
	while (true){
		n = 0; k = 0;
		ans = 0;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[x + 1];
		}
		ans = b[1];
		for (int i = 2; i <= n; i++){
			if ((i+k)==(n+1))	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			ans = max(b[i], ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (1) {
		int a[100000] = {0};
		int n, k, sum = 0, ans;

		cin >> n >> k;
		if (n == 0 && k == 0) break;

		REP(i, n) {
			cin >> a[i];
			sum += a[i];
			if (i >= k) sum -= a[i-k];
			else ans = sum;
			ans = max(ans, sum);
		}

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