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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,ans = 0,sum = 0;
  while(cin >> n >> k && n && k){
    if(cin.eof()) break;
    ans = 0,sum =0;
    vary(ll,v,n,0);
    vary(ll,imos,n+1,0);
    rep(i,n){
      cin >> v[i];
      sum += v[i];
      imos[i] += sum;
    }
    ans = -inf;
    REP(i,k,n){
      ans = max(ans,imos[i]-imos[i-k]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

int n, k, i, j, af[MAX_N], max = 0, f;

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

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

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 100004
using namespace std;

ll a[MAX];
int main(){
	int n, k;
	while(cin >> n >> k, n){
		ll ans = 0;
		a[0] = 0;
		for(int i = 1;i <= n;i++)cin >> a[i];
		for(int i = 2;i <= n;i++)a[i] += a[i-1];
		for(int i = k;i <= n;i++){
			ans = max(ans, a[i]-a[i-k]);
		}
		//for(int i = 1;i <= n;i++)cout << a[i] << " ";
		//cout << endl;
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
	int n=0, k=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);
	}

	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>
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 <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;scanf("%d %d",&N,&K);for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];ans=j;for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);return 0;}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n = 0, k = 0;
int a[10000000] = {}, b[10000000] = {};
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>
#include <string>
#include <vector>

#define rep(i, a, b) for(int i = (a); (i) < (b); i++)

using namespace std;

int main() {
	int n, k;
	vector<int> num;
	int tmp;

	while(cin >> n >> k, n) {
		rep(i, 0, n) {
			cin >> tmp;
			num.push_back(tmp);
		}

		int s = 0;
		rep(i, 1, n-k+1) {
			tmp = 0;
			rep(j, 0, k) {
				tmp += num[i+j-1];
			}

			if(s < tmp) s = tmp;
		}
		
		cout << s << endl;
	}

	return 0;
}

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

int main() {
    int n,k,i,ans=0;
    cin >> n >> k;
    while(n!=0 || k!=0){
        int a,sum[1000000],S;
        sum[0]=0;
    
        for(i=0;i<n;++i){
            cin >> a;
            sum[i+1] = sum[i] + a;
        }
    
        for(i=0;i<n-k;++i){
            S=sum[i+k]-sum[i];
            ans = max(ans,S);
        }
    
        cout << ans << endl;
        cin >> n >> k;
    }
}

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

using lint = long long;

int main(){
    int n, k;
    while(cin >> n >> k, n){
        vector<lint> sum(n + 1);
        for(int i = 1 ; i <= n ; ++i){
            cin >> sum[i];
            sum[i] += sum[i - 1];
        }

        lint ans = -(1LL << 62);
        for(int i = k ; i <= n ; ++i){
            ans = max(ans, sum[i] - sum[i - k]);
        }

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

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

const int MAX = 100005;
long long cum_sum[MAX];

int main() {
  // input
  while (true) {
    int n, k, tmp;
    cin >> n >> k;
    if (n == 0 && k == 0) break;
    for (int i = 1; i <= n; i++) {
      cin >> tmp;
      cum_sum[i] = cum_sum[i-1] + tmp;
    }

    long long ans {-MAX * n};
    for (int i = 1; i <= n-k; i++) {
      long long tmp_ans = cum_sum[i + k] - cum_sum[i];
      if (ans < tmp_ans) ans = tmp_ans;
    }
    cout << ans << endl;
  }
}