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<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 ans = 0;
    for(int j = 0; j < k; j++){
      ans += a[j];
    }
    int ab = ans;  
    //cout << "f:" << aa << endl;
    for(int i = k; i < n; i++){
      int aa = ab - a[i - k] + a[i];
      ab = aa;
      ans = aa > ans ? aa : ans;
      //cout << aaa << ":" << aa << " - " << a[i - k] << " + " << a[i] << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

using namespace std;

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

C++: int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * n);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == n) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
    }

    cout << max << endl;
    }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n , k;
    cin >> n >> k;
    while(n!=0|| k!=0){
    vector<int>a(n);
    for(int i = 0;i < n;i++){
      cin >> a.at(i);
    }
   vector<int>S(n+1);
   S.at(0) = 0;
   for(int i = 0;i < n+1 ;i++){
     S.at(i+1) = S.at(i) + a.at(i);
   }
   int ans = 0;
   for(int i = 0;i+k < n+2;i++){
     if(S.at(i+k)-S.at(i) > ans)
     ans = S.at(i+k) - S.at(i);
   }
   cout << ans << endl;
   cin >> n >> k;
    }
 }

C++: #include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int main(){
	int i,i2,sum,ans=0,n,k;
	cin>>n>>k;
	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;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int num[100001];
int main(void){
   int n,k;
   while(scanf("%d%d",&n,&k),n+k){
      for(int i = 0;i < n;i++){
         scanf("%d",&num[i]);
      }
      int ma = -2000000011;
      for(int i = 0;i <= n-k;i++){
         int part_ma = 0;
         for(int j = i;j < i+k;j++){
            part_ma += num[j];
         }
         ma = max(ma,part_ma);
      }
      printf("%d\n",ma);
   }
   return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	while(1){
	int n,k,ans=0;
	cin>>n>>k;
	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<stdio.h>

int MAX(int *num,int n,int k){
	int i,j,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	for(i = 1;i < n-k;i++){
		now = 0;
		for(j = 0;j < k;j++){
			now += num[i+j];
		}
		if(max < now)
			max = now;
	}
	return max;
}
//更新書き換え型
/*int MAX(int *num,int n,int k){
	int i,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	now = max;
	for(i = 0;i < n-k;i++){
		now += num[i+k]-num[i];
		if(max < now)
			max = now;
	}
	return max;
}*/
int main(){
	int n,k,max;
	int *num;
	int i;
	while(1){
		scanf("%d%d",&n,&k);
		if(n == 0 && k == 0)
			break;
		num = new int[n];
		for(i = 0;i < n;i++){
			scanf("%d",num+i);
		}
		max = MAX(num,n,k);
		printf("%d\n",max);
		delete[] num;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  while (1) {
    int k, n;
    cin >> n >> k;
    if ((k <= n) && (n == 0)) {
      return 0;
    }

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

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    int m = s;
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t >= m) {
        m = t;
      }
      s = t;
    }
    cout << m << endl;
  }
  return 0;
}

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

int main(void)
{
  int n, k;
  int max;
  int sum;
  int num_sequence[100000];
  while (true)
  {
    cin >> n >> k;
    if ( n == 0 && k == 0 ) break;

    //int* num_sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
      cin >> num_sequence[i];
    }

    max = -999999;
    for (int j = 0; j < n-k+1; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    //delete[] num_sequence;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<math.h>
using namespace std;
int a[100000];
int main(){
	int n,k,best,g;
	while(true){
	cin>>n>>k;
	if(n==0&&k==0)
		break;
	best=0;
	g=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i<k)
			g+=a[i];
	}
	best=g;
	for(int i=1;i<=n-k;i++){
		g+=a[i+k-1]-a[i-1];
		if(g>best)
			best=g;
	}
	cout<<best<<endl;
	}
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,sum=0,num,box[10000],ans=0;
    while(1){
    cin>>n>>k;
    if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
        cin>>num;
        for(int j=0;j<k;j++){
            if(i<k){
                sum+=num;
                box[i]=num;
                break;
            }
            else if(i>=k&&j==k-1){
                if(sum-box[0]+num>ans)ans=sum-box[0]+num;
                sum+=num-box[0];
            }
        }
        if(i>=k){
            for(int j=0;j<k;j++){
                if(j==k-1){
                    box[j]=num;
                }
                else box[j]=box[j+1];
            }
        }
    }
    cout<<ans<<endl;
    }
}

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

int main()
{
	while (1)
	{
		int a = 0, b = 0;
		double c = -1000;
		cin >> a;
		cin >> b;
		if (a == 0 && b == 0)
		{
			break;
		}
		vector<double> size;
		vector<double> s;
		for (int i = 0; i < a; i++)
		{
			int w;
			cin >> w;
			size.push_back(w);
		}
		for (int i = 0; i < a - 2; i++)
		{
			double as = 0;
			for (int ii = 0; ii < b; ii++)
			{
				as += size[i + ii];
			}
			s.push_back(as);
		}
		for (int i = 0; i < a - 2; i++)
		{
			if (c < s[i])
			{
				c = s[i];
			}
		}
		cout << c << endl;
	}
	return 0;
}