Go: package main

import "fmt"

func main() {

	for true {
		var n, k int
		fmt.Scan(&n, &k)

		if n == 0 && k == 0 {
			return
		}
		
		a := make([]int, n)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if i == 0 {
				ans[i] = a[i]
			} else {
				ans[i] = ans[i-1] + a[i]
			}
		}
		max := 0
		for i := k; i < n; i++ {
			t := ans[i] - ans[i-k]
			if max < t {
				max = t
			}
		}
		fmt.Println(max)
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n, k;
	int ans;
	while (true){
		int a[100001] = {}, b[100001] = {};
		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 <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

      if(i >= k-1){
	s = a[i];
	for(int l=1;l<k;l++) s += a[i-l];
	if(max < s) max = s;
      }
    }
    cout << max << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(void){
	int n=0, k=0, x=0;
	int *a;
	long sum  = 0;
	long msum = 0;

	scanf("%d %d", &n, &k);
	a = (int*)malloc(sizeof(int) * n);
	for(int i=0; i<n; ++i){
		scanf("%d", a+i);
	}
	scanf("%d %d", &x, &x);

	for(int i=0; i<k; ++i){
		sum += a[i];
	}
	msum = sum;

	for(int i=0; i<n-k; ++i){
		sum = sum - a[i] + a[i+k];
		if(sum > msum){
			msum = sum;
		}
	}

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

C++: #include <iostream>
#include <algorithm>
#define N 100001
using namespace std;
int main(){
  int n,k,data[N],maxv,sum,i,j;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    for(i=0;i<n;i++) cin >> data[i];
    maxv=-2000000000;
    for(i=0;i<n;i++){
      sum=0;
      if(i<=n-k){
	for(j=i;j<i+k;j++){
	  sum+=data[j];
	}
	maxv=max(maxv,sum);
      }
    }
    cout << maxv << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		vector<long long> sum;
		int num[n];
		rep(i,n)cin>>num[i];
		rep(i,n-k+1){
			long long alt=0;
			loop(j,i,i+k){
				alt+=num[j];
			}
			sum.push_back(alt);
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int n,a[100001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
cin>>a[1];
while(1){
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;

cin>>n>>k;
if(n==0&&k==0){
break;
}
cin>>a[1];
}
return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

int n,k,ar[100000];
ll result=0,buf;

int main(){
	cin.tie();	ios::sync_with_stdio(false);
	while(true){
		cin>>n>>k;

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

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

		for(int i=0;i<k;i++){
			result+=ar[i];
		}
		buf=result;
		for(int i=k;i<n;i++){
			buf+=ar[i];
			buf-=ar[i-k];
			result=max(result,buf);
		}
		cout<<result<<en;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef long long ll;
// using i32=int;using i64=long long;using ll =i64;
// using uint=unsigned int;using ull=unsigned long long;
// template<typename T> using matrix=vector<vector<T> >;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#undef NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

class Main{
public:
	ll INF=1LL<<58;
	void run(){
		while(true){
			int N,K;scanf("%d %d",&N,&K);
			if(N==0)break;
			vector<int> as(N);REP(i,N)scanf("%d",&as[i]);

			vector<ll> imos(N+1);
			for(int v=1;v<=N;v++)imos[v]=imos[v-1]+as[v-1];

			ll Mv=-INF;
			for(int i=0;i<=N;i++){
				if(i+K<=N)Mv=max(Mv,imos[i+K]-imos[i]);
			}
			cout <<Mv<<endl;
		}
	}
};
int main(){
  	Main().run();
  	return 0;
 }

C++: #include <iostream>

using namespace std;

int main()
{
	int k,n;
	int a[100000];
	while (cin>>n>>k,n!=0&&k!=0) {
		long long sum=0,max;
		for (int i=0; i<k; i++) {
			cin>>a[i];
			sum+=a[i];
		}
		max=sum;
		for (int i=k; i<n; i++) cin>>a[i];
		for (int i=k; i<n; i++) {
			sum=sum+a[i]-a[i-k];
			max=sum>max?sum:max;
		}
		cout<<max<<endl;
	}
}

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

int main() {
	while(1){
		int n, k, num[100000];
		cin >> n >> k;
		if(n == 0 && k == 0)break;
		for(int i = 0; i < n; i++)
			cin >> num[i];
	
		int ans = 0;
		for(int i = 0; i < n; i++){
			int row = 0;
			if(i >= n - (n - k))break;
			for(int j = 0; j < k && j < n; j++){
				row += num[i + j];
			}
			if(ans < row)
				ans = row;
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 100 * 1000 + 10;

double s[MAXN];
double t;

int main()
{
    int n, k;
    while(cin >> n >> k && n)
    {
        s[0] = 0;
        REP(n){cin >> t; s[i+1] = s[i] + t;}
        double ans = 0;
        for(int i = 0;i + k < n;i++){ ans = max(ans, s[i+k] - s[i]);}

        printf("%d\n", (long long)ans);
    }

    return 0;
}