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 <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, a[100009];
int main() {
	while (scanf("%d%d", &n, &m), n) {
		for (int i = 0; i < n; i++) scanf("%d", &a[i]);
		int sum = 0;
		for (int i = 0; i < m; i++) sum += a[i];
		int ret = sum;
		for (int i = m; i < n; i++) {
			sum += a[i] - a[i - m];
			ret = max(ret, sum);
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int n,k,ans;
int main(){
	while(1){
	cin>>n>>k;
	if(!n)break;
	ans=0;
	int a[n+2];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-3;i++){
		int cnt=0;
		for(int j=0;j<k;j++){
		cnt=cnt+a[i+j];
		}
		ans=max(cnt,ans);
	}
	cout<<ans<<endl;
	}

	return 0;
	

}

C++: #include <iostream>
using namespace std;
int main(){
        while(true){
                int n,number[1000000],k;
                long long int num=0,max=-1000000000;
                cin >> n >> k;
                if(n+k==0)      break;
                for(int i=0 ; i<n ; i++ )
                        cin >> number[i];
                for(int i=0 ; i<n-k ; i++ ){
                        num=0;
                        for(int j=0 ; j<k ; j++ ){
                                num+=number[i+j];
                        }
                        if(max<num)
                                max=num;
                }
                cout << max << endl;

        }
        return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    vector<int> rsw(n+1);
    rsw.at(0)=0;
    for(int i=1;i<n+1;i++){
        rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
    }
    int ans =0;
    for(int i =k;i<n+1;i++){
        if(ans < rsw.at(i) - rsw.at(i-k)){
            ans = rsw.at(i) - rsw.at(i-k);
        }
    }
    cout << ans << endl;
}

C++: #line 1 "cumulative_sum.test.cpp"
#define  PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0516"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

#line 1 "../cumulative_sum.cpp"
template<class T>
struct CumulativeSum {
  vector<T> v;

  CumulativeSum(size_t n) : v(n+1) {};
  CumulativeSum(vector<T> v_) {
    v.resize(v_.size()+1);
    for (size_t i = 0; i < v_.size(); i++) v[i+1] = v_[i];
  };

  void add(size_t i, T x) {
    v[i+1] += x;
  }

  // O(N)
  void build() {
    for (size_t i = 0; i < v.size()-1; i++)
      v[i+1] += v[i];
  }

  // O(1) sum [l, r]
  T sum(size_t l, size_t r) const {
    return l == 0 ? v[r+1] : v[r+1]-v[l];
  }

  // O(1) sum [0, r]
  T sum(size_t r) const {
    return v[r+1];
  }

  T& operator[](size_t i) {
    return v[i];
  }

  const T& operator[](size_t i) const {
    return v[i];
  }
};
#line 15 "cumulative_sum.test.cpp"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  while (1) {
    ll n, k;
    cin >> n >> k;
    if (n == 0 and k == 0) return 0;
    vl a(n);
    rep(i, n) {
      cin >> a[i];
    }

    CumulativeSum<ll> cs(a);
    cs.build();
    ll ans = -1e4;
    for (ll i = 0; i+k-1 < n; i++) {
      cmax(ans, cs.sum(i, i+k-1));
    }

    cout << ans << endl;
  }
}

C++: #include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


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

int main(void) {
  while(cin >> n >> k, !(n == 0 && k == 0)) {
    REP(i, 0, n) {
      cin >> a[i];
    }

    s = 0;
    REP(i, 0, k) {
      s += a[i];
    }

    m = s;
    REP(i, k, n) {
      s += a[i] - a[i - k];
      if(s > m) m = s;
    }

    cout << m << endl;
  }

  return 0;
}

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

C++: #include <iostream>

using namespace std;


int main() {

  int n,k;
  int a[100001];

  int max;
  int sum_seq;


  while(cin >> n >> k) {

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

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

    max=0;

    for(int i=0;i<=n-k;i++) {

      sum_seq=0;

      for(int j=i;j<i+k;j++) sum_seq+=a[j];

      if(max<sum_seq) max=sum_seq;

    }

    cout << max << endl;

  }

  return 0;

}

C++: #include <stdio.h>
int n,k,x[100005],cur,ret;
int main(){
for(;;){
	ret=-2000000000;cur=0;
	scanf("%d%d",&n,&k);if(!n)return 0;
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
		cur+=x[i];
		if(i>=k) cur-=x[i-k];
		if(i>=k-1&&ret<cur) ret=cur;
	}
	printf("%d\n",ret);
}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < 3) total += a[i];
	    else total = total + a[i] - a[i-3];
	    if(ans < total) ans = total;
    }
    cout << ans << endl;
}

C++: // This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    int max = 0;
    vector<int> a(100005, 0);
    vector<int> s(100005,0);
    while (n != 0 || k != 0) {
        int b;
        s[0] = 0
        for(int i = 0; i < n; i++) {
            cin >> b;
            s[i+1] = s[i] + b;
        }
        for (int j = 0; j < n-k; j++) {
            if(max < s[i+k] - s[i]) {
                max = s[i+k] - s[i];
            }
        }
        cout << max << endl;
        cin >> n >> k;
    }
}

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;
		}else{
			break;
		}
	}
	
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[100001],m,n;
  int mx;
  a[0]=0;
  while(cin>>n>>m&&n+m){
    for(i=1;i<n+1;i++){
      cin>>a[i];
      a[i]+=a[i-1];
    }
    mx=-1000000000;
    for(i=0;i<n-m+1;i++){
      if(a[i+m]-a[i]>mx)
	mx=a[i+m]-a[i];
    }
    cout<<mx<<endl;
  }
  return 0;
}