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 <vector>
using namespace std;



int main(){
        int n, k,max,temp,num,total;
        while(true) {  //ベクターに格納
                cin >> n>>k;
                if(n==k!=0) break;
                vector<double> v;
                total=0;
                v.push_back(total);
                for(int i=0;i<n;i++){
                  cin>>num; //入力をnumに代入
                  total+=num;
                  v.push_back(total); //ベクターvにプッシュ
                }

                max=0;
                temp=0;
                for(int i=0; i+k<=n; i++) {
                        temp=v[i+k]-v[i];
                        if(temp>max) max=temp; //tempが最も大きい数値ならmaxを更新
                        temp=0; //tempの初帰化
                }
                cout<<max<<endl;
        }
}

C++: #include <iostream>
using namespace std;
int main(){
	int s[100000];
	int n;
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int q=0;
	for(int i=0;i+k-1<=n;i++){
		int t=0;
		for(int ii=0;ii<k;ii++){
			t+=s[i+ii];
		}
		if(q<t)
			q=t;
	}
	cout<<q;
	return 0;
}

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

int main(){

  int n, k;
  
  while(cin >> n >> k, n|k){
    
    int ans = 0, data[111111] = {};
    for(int i=0;i<n;i++) cin >> data[i];
    for(int i=1;i<n;i++) data[i] += data[i-1];
    
    for(int i=0;i<n-k;i++) ans = max(ans, data[i+k] - data[i]);
    
    cout << ans << endl;
  }
  
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
  cin >> n >> k;
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    cin >> set[i];
  }

  for(int i=0,sum=0;i<n-k;i++,sum=0){
    for(int j=i;j<i+k;j++){
      sum += set[j];
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  cout << max << endl;
  }
}

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

int main() 
{
	int n = -100000;
	int a, b;
	while (cin >> a >> b, a || b) {
		vector<int>s(a);
		for (int c = 0; c < a; c++)cin >> s[c];
		int m = 0;
		for (int e = 0; e < b; e++) {
			m += s[e];
		}
		if (n < m)n = m;
		for (int d = 0; d < a - b; d++) {
			m -= s[d];
			m += s[d + b];
			if (n < m)n = m;
		}
		cout << n << endl;
	}
}

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

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

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

int main(){
  int n,k,sum,summ;
  scanf ("%d %d",&n,&k);
  while(n){
    sum=0;
    summ=0;
    vector<int> a(n);
    for(int t=0;t<n;t++){
      scanf ("%d",&a[t]);
    }
    for(int t=0;t<k;t++){
      sum+=a[t];
    }
    summ=sum;
    for(int t=k;t<n;t++){
      sum=sum+a[t]-a[t-k];
      if(sum>summ){
        summ=sum;
      }
    }
    printf("%d\n",summ);
    scanf ("%d %d",&n,&k);
  }
}

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

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

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

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


int main(){
  int n, k;
  int a[100100];
  for(;;){
    cin >> n >> k;
    if(n==0 && k==0) break;
    
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    int mx = -100000;
    for(int i=0; i<n-k; i++){
      int s = 0;
      for(int j=0; j<k; j++){
        s += a[i+j];
      }
      if(mx < s) mx = s;
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa )
{
	int temp = 0;
	int i;
	/*
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	*/
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa, 0);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0));
	}
}

C++: #include <iostream>
#include <algorithm>
#define INF (2 << 28)
using namespace std;

int main(){
    
    int n, k, a[111111];
    int sum[111111];
    
    while(cin >> n >> k, n||k){
        fill_n(sum, 111111, 0);
        for(int i = 0; i < n; i++) cin >> a[i];
        
        sum[0] = a[0];
        for(int i = 0; i < n; i++) sum[i] = sum[i - 1] + a[i];
    
        int maxi = -INF;
        for(int i = k; i < n; i++)
            maxi = max(maxi, sum[i] - sum[i - k]);
        
        cout << maxi << endl;
    }
}

C++: template<class T> void chmax(T & a, T b) { if (a < b) a = b; }
template<class T> void chmin(T & a, T b) { if (a > b) a = b; }

#define rep(i, n) for(int i=0; i<n; i++)
#include <bits/stdc++.h>
using namespace std;

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

		vector<int> a(n);
		rep(i, n) scanf("%d", &a[i]);
		vector<int> s(n + 1, 0);
		rep(i, n) s[i + 1] = s[i] + a[i];

		int res = -(1 << 30);
		rep(i, n - k) {
			chmax(res, s[i + k] - s[i]);
		}
		cout << res << endl;
	}
}

int main(void) {
	solve();

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void){
    for(int i = 0; i < 5; i++){
        long long n, k, a, sum = 0, ans = 0; 
        cin >> n >> k;
        if(n==0&&k==0){
            return 0;
        }
      int test[100001] = { 0 };
      for(int h = 0; h < n; h++){
          cin >> a;
          test[h] = a;
          if(h < k){
            sum += a;
            ans += a;
          }
      }
      for(int h = 0; h < n - k; h++){
        ans = max(ans, sum - test[h] + test[h + k]);
        sum = sum - test[h] + test[h + k];
      }
       cout << ans << endl;
   }
}