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++: // ruiseki-wa
#include <algorithm>
#include <iostream>
using namespace std;

int sum[100010];
int main(void)
{
    int n, k;
    while(1) {
        cin >> n >> k;
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) cin >> a[i];
        for(int i=0; i<n; i++) sum[i+1] = sum[i] + a[i]; // sum[i] := a[0]??????a[i-1]?????§??????(sum[0]=0)

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

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int main(){
	int i,i2,sum,ans,n,k;
	cin>>n>>k;
	while(n!=0){
		ans=0;
		for(i=0;i<n;i++)cin>>a[i];
		for(i=0;i<n-k;i++){
			sum=a[i];
			for(i2=1;i2<k;i2++)sum+=a[i+i2];
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
		cin>>n>>k;
	}
}

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

using namespace std;

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

int main(void){
  int n,k;
  while(cin>>n>>k,n+k){
    vector<int> a(n);

    rep(i,n)cin>>a[i];
    int ret = -100000;
    //cout<<k-1<<" "<<n-k+1<<endl;
    int sum = 0;
    rep(i,k)sum += a[i];
    for(int i = k ; i < n ; i ++){
      //for(int j = i-2; j <= i ; j ++)cout<<a[j]<<" ";cout<<endl;
      sum = sum + a[i] - a[i-3];
      ret = max(ret,sum);
    }
    cout<<ret<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;
#define sq(x) ((x)*(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int n, k;
	cin >> n >> k;
	queue<int> q;
	int sum = 0;
	int ans = -INT_MAX;
	rep(i, n){
		int a;
		cin >> a;
		sum += a;
		q.push(a);
		if(q.size() >= k){
			ans = max(ans, sum);
			sum -= q.front();
			q.pop();
		}
	}
	cout << ans << endl;
}

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

int main()
{
    int n,m,result;
    int num[100005];
    int memo[100000];
    while(cin >> n >> m, n+m)
    {
        for(int i = 0; i < n; i++)cin >> num[i];
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                memo[i] = num[m-j];
            }
        }
        for(int i = 0; i < n; i++)
        {
            result = max(result,memo[i]);
        }
        cout << result << endl;
    }
    return 0;
}

C++: #include<iostream>
#define INF -10000000
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0) break;
    int s[n],ans=INF;
    for(int i=0;i<n;i++) cin >> s[i];
    for(int i=m-1;i<n;i++){
      int su = 0;
      for(int j=i-m+1;j<=i;j++) su += s[j];
      if(ans<su) ans = su;
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

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

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);
    }

    while(1){
      s = m;
      ans_t = 0;

      while(1){
        if(s == k){
          break;
        }
        ans_t += a_n[s];
        s++;
      }

      if(m == 0){
        ans = ans_t;
      }
      else{
        if(ans_t > ans){
          ans = ans_t;
        }
      }

      k++;
      m++;

      if(k == n+1){
        break;
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}