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>
#define ini 0
using namespace std;


int rlay[100001];

int main (){

while (1){
memset(rlay, 0,sizeof(rlay));

int n,k,input,ansmax=0;
cin>>n>>k;
if (n==0&&k==0)break;

rlay[0]=ini;
for (int i=1;i<=n;i++){
        cin>>input;
        rlay[i]=input+rlay[i-1];
}

for (int i=n;i-k>0;i--){
        ansmax = max ( rlay[i]-rlay[i-k] ,ansmax );
}

cout<<ansmax<<endl;

}
return 0;
}

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


int main(){
    int n, k;
    while (cin >> n >> k, n || k){
	vector<int> a;
	vector<int> s;

	int aa;
	for (int i = 0; i < n; i++){
	    cin >> aa;
	    a.push_back(aa);
	    s.push_back(0);
	}
	
	for (int i = 0; i < n - k; i++){
	    for (int j = i; j < i + k; j++){
		s[i] += a[j];
	    }
	}

	sort(s.begin(), s.end(), greater<int>());
	
	cout << s[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,k,box[5000]={0},ans=0,sum=0,summ;
int main(){
    cin >> n >> k;
    while(1){
        for(int i=0;i<k;i++){
            cin >> box[i];
            if(box[0]==0&&box[1]==0)break;
            sum+=box[i];
            }
            if(box[0]==0&&box[1]==0)break;
          for(int i=k;i<n;i++){
                cin >> box[i];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;

    }
    return 0;
}

C++: #include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 100000;
int a[MAX_N];

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

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

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

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

	return 0;
}

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

#define MAX_N 100000

using namespace std;

int n, k;
int a[MAX_N+1];

int main()
{
	while(true)
	{

	int max_v = 0;
	cin >> n >> k;

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

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

	for(int i = 0; i + k <= n ; i++)
	{
		int value = 0;

		for(int j = 0; j < k; j++)
		{
			value += a[i + j];
		}

		max_v = max(max_v, value);
	}	

	cout << max_v << endl;

	}

	return 0;
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,k;
	while(cin >> n >> k , n){
		int d[100001] = {0};
		for(int i=1;i<=n;i++){
			int t;cin >> t;
			d[i] = d[i-1] + t;
		}
		int ans = 0;
		for(int i=1;i+k-1<=n;i++){
			ans = max(ans,d[i+k-1]-d[i-1]);
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>

using namespace std;

int n,k,s,smax;
int a[100000];
int s1,s2;

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n;l++){
		s2=s1-a[l]+a[n-l];
		if(s1>smax) smax=s1;
		s1=s2;
	}
		printf("%d",smax);
	return 0;
}

C++: #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower


using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;


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

    return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
long long sin[100001];
int main(){
	while(1){
	memset(sin,0,sizeof(sin));
	long n,k;
	int i,j,max=0,x;
		cin>>n>>k;if(n==0&&k==0)break;
	for(i=1;i<=n;i++){
		cin>>sin[i];
	}
	x=0;
	for(j=1;j<=k;j++){
		x+=sin[j];
	}
		for(i=k+1;i<=n;i++){
			x+=sin[i];
			x-=sin[i-k];
			if(x>max)max=x;
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値

int main() {
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> 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];

        // 答えを求める
        long long res = -INF; // 最初は無限小の値に初期化しておく
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
const int INF = 1 << 30;
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int &x : a)cin >> x;
	int pos = 0;
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	int max = sum;
	for (int i = 0; i < n - k; i++) {
		sum += a[i + k] - a[i];
		max = std::max(max, sum);
	}
	cout<<max<<endl;
	return 0;
}