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<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	while(1){
        int n,k;
        int sum = 0,mx = 0;
        int ans[10000] = {0};
        cin >> n >> k;
        if(n == 0 && k == 0) break;
        for(int i = 0; i < n; i++) cin >> ans[i];
        for(int i = 0; i < k; i++){
            sum += ans[i];
        }
        mx = sum;
        for(int i = k; i < n; i++){
            sum += ans[i];
            sum -= ans[i-k];
            mx = max(mx,sum);
        }
        cout << mx << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;

ll sum[100010];
ll a[100010];

int main()
{
	while (1) {
		ll n, k;
		cin >> n >> k;
		if (n == 0 && k == 0)break;

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

		sum[1] = a[1];
		for (int i = 2; i <= n; i++) {
			sum[i] = sum[i - 1] + a[i];
		}

		ll mx = 0;
		ll ans = 0;
		for (int i = k; i <= n; i++) {
			mx = sum[i] - sum[i - k];
			ans = max(mx, ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

ll solve(int n, int k) {
    ll a[n+1];
    a[0] = 0LL;
    for(int i=1;i<=n;++i){
        cin >> a[i];
        a[i] += a[i-1];
    }

    ll ans = -(1LL << 60);
    for(int i=1;i<=n-k;++i) {
        ans = max(ans, a[i+k-1]-a[i-1]);
    }
    return ans;
}

int main() {
    int n, k;

    while(cin >> n >> k && n) {
        cout << solve(n, k) << endl;
    }
}

C++: #include <iostream>

using namespace std;

#define NMAX 5000

int n, k;
int a[NMAX];

int solve() {
    int max_sum = -10000000;
    int sum = 0;
    for (int i = 0; i + k < n; i++) {
        for (int j = i; j < i + k; j++) {
            sum += a[j];
        }
        if (sum > max_sum) max_sum = sum;
        sum = 0;
    }
    return max_sum;
}

int main() {
    while (true) {
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        cout << solve() << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (!n && !k) return 0;
    int a[n], result = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        result += a[i];
    }
    cout << result << endl;
    for (int i = k; i < n; i++)
      result = max(result, result - a[i-k] + a[i]);
    cout << result << endl;
  }
}

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

using namespace std;

int n,k,s,ans,term,ans_t;
vector<int> a_n;
int m,t;

int main()
{

  while(1){
    m = 0;
    cin>>n>>k;

    if(n == 0 && k == 0){
      break;
    }

    for(int q = 0;q < n;++q){
      cin>>term;
      a_n.push_back(term);
    }

    for(int q = 0; q < n+1-k; ++q){
      s = q;
      ans_t = 0;

      for(;s<k+q;++s){
	ans_t += a_n[s];
      } 

      if(q == 0){
        ans = ans_t;
      }
      else{
        if(ans_t > ans){
          ans = ans_t;
        }
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = (1 << 29);

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

C++: #include <stdio.h>
int main(){
    int n,k,a[1000000],top,sum;
    while(1){
        scanf("%d%d",&n,&k);
        if(n==0)return 0;
        sum=0;
        for(int i=0;i<k;i++){
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        top=sum;
        for(int i=k;i<n;i++){
            scanf("%d",&a[i]);
            sum+=a[i];
            sum-=a[i-k];
            if(sum>top)top=sum;
        }
        printf("%d\n",top);
    }
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)

bool has_key_using_count(map<char, char> &m, char n){
    if (m.count(n) == 0){
		//cout << "m doesn't have " << n << "." << endl;
        return false;
    }
    else{
        //cout << "m has " << n << "." << endl;
        return true;
    }
}

int main()
{
	//ifstream cin("sample.txt");

	int n = 0, k = 0, max = 0, tmp = 0, sumTmp = 0;
	
	vector<int> series, seriesK, sum;

	series.clear();
	seriesK.clear();
	sum.clear();
	// 読み込み
	cin >> n >> k;
	rep(i, n) {
		cin >> tmp;
		series.push_back(tmp);
	}

	// 複数のseriesKの最大値を求める
	for (int i = 1; i < n-k+1; i++) {
		seriesK.clear();
		sumTmp = 0;

		// Kまでの数列作成
		for (int j = i; j < i+k; j++) {
			seriesK.push_back(series[j]);
			sumTmp += series[j];
		}

		// 和を求めて格納
		sum.push_back(sumTmp);
	}

	// 和の中で最大のものを出力
	rep(i, sum.size()) {
		if (sum[i] > max) {
			max = sum[i];
		}
	}

	// 出力する
	cout << max << endl;

	return 0;
}

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

using namespace std;

int main(void) {
	int n, k, in, sum, res;
	vector<int> val;
	int i, j;

	while(true) {
		cin >> n >> k;
		if((n == 0 && k == 0) || cin.eof()) { break; }
		val.clear();
		res = 0;
		for(i = 0; i < k; i++) {
			cin >> in;
			val.push_back(in);
		}
		sum = 0;
		for(i = 0;i < k; i++) {
			sum += val[i];
		}
		res = max(res, sum);
		for(i = k; i < n; i++) {
			val.erase(val.begin());
			cin >> in;
			val.push_back(in);
			sum = 0;
			for(j = 0;j < k; j++) {
				sum += val[j];
			}
			res = max(res, sum);
		}
		cout << res << endl;
	}

	return 0;
}

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

using namespace std;

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

		m[0] = a[0];
		for (int i = 0;i < n;i++)
			m[i + 1] = m[i] + a[i];

		s = m[k] - m[0];
		for (int i = 0;i < n - k + 1;i++)
		{
			b = m[i + k + 1] - m[i + 1];
			if (s < b) 
				s = b;

		}

	}
	cout << s << endl;
	return 0;
}

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 << max << endl;
        cin >> n >> k;
    }
}