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 <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int n, k;
	while (cin >> n >> k) {
		vector<int> num;
		if (n == 0) {
			break;
		}
		int o;
		for (int i = 0; i < n; i++) {
			cin >> o;
			num.emplace_back(o);
		}
		int m = 0;
		for (int i = 0; i < n - k + 1; i++) {
			m = max(m, num[i] + num[i + 1] + num[i + 2]);
		}
		cout << m << endl;
	}
}

C++: #include<iostream>

using namespace std;

int main(){

  int in, k;

  while(cin >> in >> k){
    if(in == 0 && k == 0) break;
    int data[in];
    int sum;

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

    int tmp = 0;

    for(int i = 0; i < k; i++){
      tmp += data[i];
    }
    sum = tmp;
    int num = 0;

    for(int i = k; i < in; i++){
      tmp -= data[num];
      num++;
      tmp += data[i];
      if(i == 0 || sum < tmp) sum = tmp;
    }

    cout << sum << endl;
  }
  return 0;
}

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

int main(){
while(1){
	int n,k,a[100002],sum=0,ans=0;
	scanf("%d%d",&n,&k);
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	ans=sum;
	for(int i=0;k<n;i++){
		sum-=a[i];
		sum+=a[k];
		if(ans<sum)ans=sum;
		k++;
	}
	printf("%d\n",ans);
}
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int n,k;
    while (cin >> n >> k) 
    {
        if (n == 0 && k==0) 
        {
            break;
        }
        vector<int> vec(n);
        vector<int> sum(n -k +1);
        int sum_max=0;
        int input;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];
        }
        for (int i = 0; i < n - k + 1; i++) 
        {
            sum[i]=0;
            for (int j = 0; j < k; j++) 
            {
                sum[i] += vec[i + j];
            }
            if (sum_max < sum[i]) 
            {
                sum_max = sum[i];
            }
        }
        cout << sum_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+1){
    if (m < S[i+k]-S[i])
      m = S[i+k]-S[i];
    i++;
  }
  cout << m << 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;
    int sum = 0;
    rep(i,k)sum += a[i];
    for(int i = k ; i < n ; i ++){
      sum = sum + a[i] - a[i-k];
      ret = max(ret,sum);
    }
    cout<<ret<<endl;
  }
}

C++: #include <cstdio>

using namespace std;

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

int main(){
	scanf("%d %d\n",&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-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
		printf("%d",smax);
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	long long int ans;
	int num[100001];
	int n,k;
	int a;
	ans=0;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0 && k==0)break;
		for(a=0;a<n;a++)scanf("%d",&num[a]);
		for(a=0;a<k;a++){
			ans+=num[a];
		}
		for(a=k;a<n;a++){
			ans=max(ans,ans+num[a]-num[a-k]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;

int main()
{
	int K,N;
	while(cin>>N>>K && (K || N)){
		ll res = 0, ans = 0;
		queue<int> A;
		for(int i = 0; i < N; i++){
			int buf;
			cin>>buf;
			res += buf;
			A.push(buf);
			if(i >= K){
				res -= A.front();
				A.pop();
				ans = max(ans, res);
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef priority_queue<int> PQ;

int main(){
	int n,k;

	while(true){
		PQ sum;
		vector<int> a;

		cin>>n>>k;
		if(n==0&&k==0) break;

		for(int i=0;i<n;i++){
			int t;
			cin>>t;
			a.push_back(t);
		}

		for(int i=0;i<=n-k;i++){
			int t=i+k-1,s=0;
			for(int j=i;j<=t;j++){
				s+=a[j];
			}
			sum.push(s);
		}

		cout<<sum.top()<<endl;

	}
	return 0;
}

C++: #include<iostream>
#define INF -10000000000000000;
using namespace std;

long long int num[100100];


int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=INF;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<100100;i++){
            num[i]=0;
            if(num[i+1]==0)break;
        }
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i<m)sum+=num[i];
        }
        cout<<sum<<endl;
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        cout<<ans<<endl;
        ans=INF;
        sum=0;
        }
    return 0;
}

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

int main(){
  int n,k;
  int a[1000000];

  for(;;){
    scanf("%d %d",&n,&k);
    if(!n && !k)break;

    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    int sum = 0;
    for(int i=0;i<k;i++)sum += a[i];
    int m = sum;
    for(int i=k;i<n;i++){
      sum += a[i] - a[i-k];
      m = max(m,sum);
    }
    printf("%d\n",m);
  }
}

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

using namespace std;

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

		m[0] = 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;
const int SIZE=100001;
int a[SIZE]={00},b[SIZE]={00},c[SIZE]={00};

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(1){
	int n,k,x=0,ma=0,p=0,q=0;
	cin>>n>>k;
		q=k-1;
		if(n==0 && k==0)
		break;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
		for(int i=0;i<k;i++){
			x+=a[i];
		}
		ma=max(ma,x);
		for(int i=0;i<n-k;i++){
			q++;
			x+=a[q];
			x-=a[p];
			p++;
			ma=max(ma,x);
		}
	cout<<ma<<endl;
	}
return 0;
}