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;

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) elems.push_back(item);
      item.clear();
    }
    else item += ch;
  }
  if (!item.empty()) elems.push_back(item);
  return elems;
}

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

signed main()
{
  int n, m;

  while (cin >> n >> m, n + m){
    int a[n], maxsum = 0;

    rep(i, n) a[i] = in();
    rep(i, m) maxsum += a[i];
    reps(i, m, n) maxsum = max(maxsum, maxsum - a[i - m] + a[i]);
    print(maxsum);
  }

  return (0);
}

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



int main(){
        int n, k;
        vector<double> v;
        cin >> n>>k;

        int num=0;
        for(int i=0; i<n; i++) {  //ベクターに格納
                cin>>num; //入力をnumに代入
                v.push_back(num); //ベクターvにプッシュ
        }


        int max=0;
        int temp=0;
        for(int i=0; (i+k)<=n; i++) {
                for(int j=0; j<k; j++) {
                        temp+=v[i+j]; //tempにvのiからi+k番目までの総和を代入
                }
                //cout<<temp<<endl;
                if(temp>max) max=temp;  //tempが最も大きい数値ならmaxを更新
                temp=0; //tempの初帰化
        }
        cout<<max<<endl;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(N);
        cin >> a;
        S[0]=0;
        for(int i=1;i==n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        int x=S[k];
        for(int l=1;l==n-k;l++){
            if(x<S[k+l]-S[l]){
                x==S[k+l]-S[l];
            }
        }
            cout << x << endl;;
            cin >> n >> k;
        }

    }

}

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

int main(){
  int n,k,tmp,max;
  int a[111111];
  while(1){
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    max = 0;
    tmp = 0;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<k;j++){
	if(i+k > n){
	  tmp = 0;
	}
	else tmp += a[i+j];
	if(j == k-1){
	  if(tmp > max){
	    max = tmp;
	    tmp = 0;
	  }
	  else tmp = 0;
	}
      }
    }
    cout << max << endl;
  }
}

C++: #include <stdio.h>

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

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, maxTmp = 0;
	
	vector<int> series, seriesK, sum;

	while (cin >> n >> k) {
		if (n == 0 && k == 0) {
			break;
		}
		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);

			// 現在の和の中で最大のものを計算
			if (sumTmp > maxTmp) {
				maxTmp = sumTmp;
			}
		}

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

		// 出力する
		cout << maxTmp << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N, K;
    while(cin >> N >> K) {
        if(N == 0) break;
        vector<ll> a(N);
        for(int i = 0; i < N; ++i) cin >> a[i];

        vector<int> s(N+1, 0);
        for(int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        ll res = -INF;
        for(int i = 0; i <= N-K; ++i) {
            ll val = s[K+i];
            if(res < val) res = val;
        }
        cout << res << endl;
    }

}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
    	if(i < 3) total += a[i];
	    else total = total + a[i] - a[i-3];
	    if(ans < total) ans = total;
    }
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k;
ll a[100100];
ll sum[100100];
vector<ll> ans;

int main(){
	while (cin >> n >> k&&n + k){
		fill(a, a + 100100, 0);
		fill(sum, sum + 100100, 0);
		ll MAX = -1000000000;
		REP(i, n)cin >> a[i];
		REP(i, n){
			if (i == 0)sum[i] = a[i];
			else sum[i] = sum[i - 1] + a[i];
		}
		ans.push_back(sum[k-1]);
		REP(i, n - k){
			ans.push_back(sum[i + k] - sum[i]);
		}
		REP(i, ans.size()){
			MAX = max(MAX, ans[i]);
		}
		cout << MAX << endl;
		ans.clear();
	}
}