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<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

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

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

C++: #include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

// f : 二項演算 Group * Group -> Group
// g : 逆元関数 Group -> Group
// G1 : 単位元
template<typename Group>
class CumulativeSum {
	std::vector<Group> elements;
	std::vector<Group> sum;
	
	bool built;
	
	using F = std::function<Group(Group, Group)>;
	using G = std::function<Group(Group)>;
	
	const F f;
	const G g;
	const Group G1;
	
	private:
	void build() {
		if(built) return;
		built = true;
		sum.assign(elements.size() + 1, G1);
		for(int i = 0; i < elements.size(); i++) sum[i + 1] = f(sum[i], elements[i]);
	}
	public:
	CumulativeSum(F f, G g, Group G1) : f(f), g(g), G1(G1) {
		built = false;
		elements.clear();
		sum.clear();
	}
	CumulativeSum(F f, G g, Group G1, std::vector<Group> vec) : f(f), g(g), G1(G1) {
		built = false;
		elements.swap(vec);
		sum.clear();
	}
	void swap(std::vector<Group> vec) {
		built = false;
		elements.swap(vec);
	}
	void add(Group x) {
		built = false;
		elements.push_back(x);
	}
	void pop_back() {
		if(!elements.size()) return;
		built = false;
		elements.pop_back();
	}
	Group get(int k) { // [0, k)
		build();
		return sum[k];
	}
	Group get(int a, int b) { // [a, b)
		build();
		return f(g(sum[a - 1]), sum[b]);
	}
	int size() {
		return elements.size();
	}
};

int main() {
	int n, k;
	while(scanf("%d%d", &n, &k) and (n and k)) {
		std::vector<i64> a(n);
		for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
		CumulativeSum<i64> cs([](i64 a, i64 b) { return a + b; }, [](i64 a) { return -a; }, 0, a);
		
		i64 ma = -(1LL << 60);
		for(int i = 1; i + k - 1 <= n; i++) ma = std::max(ma, cs.get(i, i + k - 1));
		printf("%lld\n", ma);
	}
	return 0;
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){for(i=s=0;i<n;i++<k&&(M=s+=a[i-1]))std::cin>>a[i];for(i=k;i<n;M<s&&(M=s))s+=a[i]-a[i++-k];}}

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

using namespace std;

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

int main() {
	while (1) {
		int a[100000] = {0};
		int n, k, sum = 0, ans;

		cin >> n >> k;
		if (n == 0 && k == 0) break;

		REP(i, n) {
			cin >> a[i];
			sum += a[i];
			if (i >= k) sum -= a[i-k];
			else ans = sum;
			ans = max(ans, sum);
		}

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

C++: #include<iostream>
main(){
  for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))
    for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<i)*a[i-k],i++,k<i&&M<s&&(M=s))std::cin>>a[i];
}