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

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

    long long sum=0, ans=0;
    for(int i=0; i<k; i++){
        sum+=a[i];
        ans=max(ans, sum);
    }
    for(int i=0; i<n-k; i++){
        sum-=a[i];
        sum+=a[i+k];
        ans=max(ans, sum);
    }

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

C++: #include <iostream>

using namespace std;

int main() {
  int k, n;
  while (1) {
    cin >> n >> k;

    if ((k == 0 && n == 0)) {
      return 0;
    }
    int a[100000];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t > s) {
        s = t;
      }
    }
    cout << ' '<<  s << endl;
  }
  return 0;
}

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

int main(){
	int n,k,a[100001];
	while(1){
		a[0] = 0;
		cin >> n >> k;
		if(n == 0 && k == 0) break;
		for(int i = 0;i < n;i++) {
			int t;
			cin >> t;
			a[i + 1] = a[i] + t;
		}
		int ma = -INF;
		for(int i = 0;i <= n - k;i++){
			ma = max(ma,a[i + k] - a[i]);
		}
		cout << ma << endl;
	}
	return 0;	
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long m[100000][2];
int main(){
while(1){
long long n,k,i,j,x=0;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=0;i<n;i++)cin>>m[i][0];
m[0][1]=m[0][0];
for(i=1;i<n;i++){
m[i][1]=m[i-1][1]+m[i][0];
}
for(i=k-1;i<n;i++){
x=max(x,m[i][1]-m[i-k][1]);
}
cout<<x<<endl;
return 0;
}
}

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

using namespace std;

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

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		for (int i = 0; i < n; i++){
//			printf("%2d ", data[i]);
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			if (!(i == 0)) max = MAX(max, data[i + k - 1] - data[i - 1]);
			else max = data[i + k - 1];
		}
//		printf("\n");
		/*
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}*/
		
		printf("%d\n", max);
	}
	
	return (0);
}

C++: #include<stdio.h>

int main(void){
	int i,n,k,sum,max;
	int N[15000];

	while(0==0){
		scanf("%d %d",&n,&k);
		sum=0;
		if(n==0 && k==0) break;

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

		for(i=0;i<k;i++)
		    sum+=N[i];//初期値
		
		max=sum;

		for(i=k;i<n;i++){
			sum+=N[i];
			sum-=N[i-k];
			if(sum>max)max=sum;
		}

		printf("%d\n",max);
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

int n,k;
vi a;

int main(){
	while(1){
		cin>>n>>k;
		if(!n&&!k) break;
		a=vi(n);
		ll sum=0,ans;
		for(auto i=a.begin();i!=a.end();i++){
			cin>>*i;
			if(i<a.begin()+k) sum+=*i;
		}
		ans=sum;
		for(auto i=a.begin()+k;i!=a.end();i++){
			sum+=*i-*(i-k);
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int a[200000];

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

C++: #include<cstdio>
#include<algorithm>
#define INF 1000000000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int a[100000];
int main(){
	int n, k;
	while (scanf("%d%d", &n, &k), n){
		rep(i, n)
			scanf("%d", &a[i]);
		int Max = -INF;
		rep(i, n - k + 1){
			int sum = 0;
			rep(j, k){
				sum += a[i + j];
			}
			Max = max(Max, sum);
		}
		printf("%d\n", Max);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  int n,k;
  int a[100001];
  cin>>n>>k;
  REP(i,n)cin>>a[i];
  int sum = 0;
  int mx;
  REP(i,k){
    sum+=a[i];
  }
  mx = sum;
  for(int i=k;i<n;i++){
    sum-=a[i-k];
    sum+=a[i];
    mx = max(sum,mx);
  }
  cout<<mx<<endl;
  return 0;
}

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

int main(){
  long long n,k;

  while(1) {
    long long ans=-1000000000;
    cin>>n>>k;
    if(n == 0 and k == 0) break;
    long long a[n];for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<n-k+1;i++){
      long long temp=0;
      for(int j=i;j<i+k;j++){
        temp+=a[j];
      }
      ans=max(temp,ans);
    }
    cout<<ans<<endl;
  }
}