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>

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<vector>
using namespace std;
int main(){
	vector<int> sum;
	int n,m,x,max;
	while(cin>>n>>m,n||m){
	cin>>x;
	sum.push_back(0);
	sum.push_back(x);
	max=-1000000;
	for(int i=2;i<=n;i++){
		cin>>x;
		sum.push_back(sum[i-1]+x);
	}
	for(int i=0;i<n;i++){
		if(sum[m+i]-sum[i]>max)
		max=sum[m+i]-sum[i];
	}
	cout<<max<<endl;
		sum.clear();
	}
	return 0;
}

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

int seq[100000];
int n,k;

int req(int rem, int i)
{
	rem -= seq[i];
	rem += seq[i+k];
	return rem;
}
int main()
{
	while(cin >> n >> k){
		if(n==0&&k==0)
			break;
		for(int i=0;i<n;i++){
			cin >> seq[i];
		}
		int rem=0;
		for(int i=0;i<k;i++){
			rem+=seq[i];
		}
		int remm = rem;
		for(int i=0;i<n-k;i++){
			rem = req(rem,i);
			remm = max(remm,rem);
		}
		cout << rem << endl;
	}
	return 0;
}

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

int seq[100000];
int n,k;

int req(int rem, int i)
{
	rem -= seq[i];
	rem += seq[i+k];
	return rem;
}
int main()
{
	while(cin >> n >> k){
		if(n==0&&k==0)
			break;
		for(int i=0;i<n;i++){
			cin >> seq[i];
		}
		int rem=0;
		for(int i=0;i<k;i++){
			rem+=seq[i];
		}
		for(int i=0;i<n-k;i++){
			rem = max(rem,req(rem,i));
		}
		cout << rem << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, k;
    while(cin>>n>>k, n){
        vector<int> a(n);
        for(int i=0; i<n; i++) cin>>a[i];

        vector<ll> sum(n+10, 0);
        for(int i=1; i<=n; i++) sum[i]=sum[i-1]+a[i-1];

        ll ans=-INF;
        for(int i=1; i+k-1<=n; i++){
            chmax(ans, sum[i+k-1]-sum[i-1]);
        }
        cout << ans << endl;
    }
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int main() {
	int n, k;
	while (scanf("%d %d",&n,&k)&&n!=0) {
		vector<int> a(n);
		for (int i=0; i<n; i++) scanf("%d",&a[i]);
		int max=0;
		for (int i=0; i<k; i++) max+=a[i];
		int tmp=max;
		for (int i=0; i<n-k; i++) {
			tmp=tmp-a[i]+a[i+k];
			if (tmp>max) max=tmp;
		}
		printf("%d\n",max);
	}
}

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

int num[100000];
int main(){
    int n, k;
    int a;
    int i;
    long long int now;
    long long int max;
    cin >> n >> k;
    while(n || k){
        for(i=0;i<n-k;i++){
            num[i] = 0;
        }
        now = 0;
        max = 0;
        for(i=0;i<k;i++){
            cin >> a;
            num[i] -= a;
            now += a;
        }
        for(;i<n-k;i++){
            cin >> a;
            num[i] -= a;
            num[i-k] += a;
        }
        for(;i<n;i++){
            cin >> a;
            num[i-k] += a;
        }
        for(i=0;i<n-k+1;i++){
            if(max < now){
                max = now;
            }
            now += num[i];
        }
        cout << endl;
        cout << max << endl;
        cin >> n >> k;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n=0, k=0;
		double a[100001] = {}, b[100001] = {}, 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[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		else{
			cout << ans << endl;
		}
	}
	return 0;
}

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

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

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

		int s[10000] = {};
		for (int i = 0;i < n - k;i++) {
			for (int j = 0;j < k;j++) {
				s[i] += a[i + j];
			}
		}
		sort(s, s + n - k + 1);
		cout << s[n - k] << endl;
	}
	return 0;
}

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

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

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

int main(){
int n,k,s,ans;
int a[100001];
while(cin>>n>>k){
if(n==0&&k==0)break;
for(int i=0;i<n;i++)cin>>a[i];
s=0;
for(int i=0;i<n-k+1;i++){
if(i==0)for(int j=i;j<i+k;j++)s+=a[j];
if(i!=0){s-=a[i-1]; s+=a[i+k-1];}
if(i==0)ans=s;
if(s>ans)ans=s;}
cout<<ans<<endl;}}