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>

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) {
        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) break;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        printf("%d\n", solve());
    }
    return 0;
}

C++: #include<iostream>
#include<stdio.h>

using namespace std;


int main(){

while(1){
    int n, k;
    cin>> n>> k;
    if(n==0&&k==0) break;
    int a[n];
    for(int i=0; i<n; i++){
        cin>> a[i];
    }
    int s[n+1];
    fill(s, s+n+1, 0);
    for(int i=0; i<n; i++){
        s[i+1]=s[i]+a[i];
    }
    int ans=-100100100;
    for(int i=k; i<=n; i++){
        ans=max(ans, s[i]-s[i-k]);
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
const long long int INF =  1LL<<60; 
int main() {
    while(true) {
        int N, K;
        cin >> N >> K;
        if(N == 0 && K == 0) {
            break;
        }
        vector<int> a(N);
        for(int i = 0; i < N; i++) {
            cin >> a[i];
        }
        int max = 0;
        vector<int> s(N+1);
        for(int i = 0; i < N; i++) {
            s[i+1] = s[i] + a[i];
        }
        long long int res = -INF;
        for(int i = 0; i+K <= N; i++) {
            long long int value = s[i+K] - s[i];
            if(res < value) {
                res = value;
            }
        }
            cout << res << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n, k;
		double a[100001] = {}, b[100001] = {}, ans;
		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[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		else{
			cout << ans << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int n,k;
int main(){
	while(cin>>n>>k){
	int ans=0;
	if(n==0 && k==0){
		break;
	}
	int a[n+2];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-3;i++){
		int cnt=0;
		for(int j=0;j<k;j++){
		cnt=cnt+a[i+j];
		}
		ans=max(cnt,ans);
	}
	cout<<ans<<endl;
	}

	return 0;
	

}

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;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < 3){
    	    total = total + a[i];
    	}else{
    	    total = total + a[i] - a[i-3];
    	}
	    if(ans < total){
	        ans = total;
	    }
    }
    cout << ans << endl;
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa )
{
	int temp = 0;
	int i;
	/*
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	*/
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0));
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	while(true){
	int n , k ,ans;
	double a[100001] = {}, b[100001] = {};
	cin >> n >> k;
	if (n==0||k==0)	break;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n-k+1; i ++){
		b[i] = a[i] + a[i + 1] + a[i + 2];
		if (b[i]>b[i - 1]){
				ans = b[i];
		}
	}
	cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  while(true){
    int a[100000] = {0};
    int n, k;
    cin >> n >> k;
    if(!n)
      break;
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int aa = 0;
    for(int i = 0; i < k; i++){
      aa += a[i];
    }
    //cout << "f:" << aa << endl;
    for(int i = k; i < n; i++){
      int aaa = aa - a[i - k] + a[i];
      aa = aaa > aa ? aaa : aa;
      //cout << "f:" << aa << " n:" << aaa << endl;
    }
    cout << aa << endl;
  }
  return 0;
}

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

int main()
{
	int n,k;

	int suu[100000 + 100] = { 0 };
	int a;
	int i;
	int mx;

	cin >> n >> k;

	while (n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{

			cin >> a;

			suu[i] = a + suu[i - 1];

			if (i >= k)
			{
				if (mx < suu[i] - suu[i - k])
				{
					mx = suu[i] - suu[i - k];
				}

			}

		}

		/*
		for (i = k; i <= n; i++)
		{
			if (mx < suu[i] - suu[i - k])
			{
				mx = suu[i] - suu[i - k];
			}

		}
		*/

		cout << mx << endl;


		cin >> n >> k;
		mx = 0;
	}
	return 0;
}

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

int main(){
	int n, k, a[100000] = {};
	long long int sum = -10000000, tmp;
	while(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++){
			tmp = 0;
			for(int j = 0;j<k;j++){
				tmp += a[i + j];
			}
			if(sum < tmp) sum = tmp;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main(){
	int n, k;
	vector< int > a;
	vector< int > r;
	
	while(cin >> n >> k, n){
		a.RS(n);
		r.RS(n - k + 1);
		
		REP(i, n) cin >> a[i];
		
		REP(i, k) r[0] +=  a[i];
		
		FOR(i, k, n){
			r[i-k+1] = r[i-k] + a[i] - a[i-k];
		}
		cout << *max_element(ALL(r)) << endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n, k;
	int cnt, cnt_max = 0, masatoy;
	cin >> n >> k;
	while (n != 0 && k != 0) {
		for (int i = 1; i <= n; i++) {
			cin >> masatoy;
			if (1 <= i&&i <= n - k + 1) {
				cnt = 0;
				for (int j = 0; j < k - 1; j++) {
					cnt += masatoy + j;
				}
				//cout << cnt << endl;
				if (cnt > cnt_max) {
					cnt_max = cnt;
				}
			}
		}
		cout << cnt_max << endl;
		cnt_max = 0;
		cin >> n >> k;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
	for (;;){
		int a,b,c,d,max=0,m;
		cin>>a>>b;
		int e[a]={0};
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>e[c];
		}
		m=a-b;
		for (c=0;c<a-m;c++){
			for (int y=1;y<b;y++) e[c]=e[c]+e[c+y];
			if (max<e[c]) max=e[c];
	}
		cout<<max<<endl;
	}
	return 0;
}

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

int main()
{
int n,k;
cin >> n >> k;
while(n!=0||k!=0){
  int i=0, a[n], S[n-1];
  S[0] = 0;
  while(i < n){
    cin >> a[i];
    if (i>=1)
      S[i] = S[i-1]+a[i-1];
    i++;
  }
  i = 0;
  int m = S[k-1]-S[0];
  while(k+i<=n){
    if (m < S[i+k]-S[i])
      m = S[i+k]-S[i];
    i++;
  }
  cout << m << endl;
cin >> n >> k;
}}