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>
#include<iostream>
using namespace std;
int num[1000000];
int main()
{
	int n, k, ans = 0, sans=0;
	while (1)
	{
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0)
			break;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &num[i]);
		}
		for (int i = 0; i < n - k; i++)
		{
			for (int j = i; j < i + k; j++)
			{
				sans += num[j];
			}
			if (ans < sans)
				ans = sans;
			sans = 0;
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=-100000000,sum;
	cin>>n>>k;
	while(n!=0){
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
	cin>>n>>k;
	}
}

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

int main(){
  int numn,lisn,num;
  vector<int> outp;
  int outn = 1;
  for(int l = 0;;l++){
    cin >> numn >> lisn;
    if(numn == 0 && lisn == 0){
      break;
    }
    outp.resize(l+1,0);
    vector<int> lists(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> lists[n];
    }
    for(int k = 0;k<numn-lisn+1;k++){
      outn = 0;
      for(int c = 0;c<lisn;c++){
        outn += lists[c+k];
      }
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << endl;
  }
}

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

using namespace std;

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

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=0;

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#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>
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>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
	++n;
	if(noww>w || nowh>h) return 0;
	if(noww==w && nowh==h) return 1;
	int ret=0;
	n=0;
	if(n)
	ret+=dfs(w,h,++noww,nowh,n,b);
	ret+=dfs(w,h,noww,++nowh,n,b);
	ret+=dfs(w,h,++noww,nowh,n,b);
	ret+=dfs(w,h,noww,++nowh,n,b);
	return ret;
}

int main()u{
	int w,h;
	cin >> w >> h;
	cout << dfs(w,h,1,1,2,0) << endl;
	return 0;
}
*/

int main(){
	int n,k;
	while(cin >> n >> k&&n!=0&&k!=0){
		int maxi=0;
		vector<int> seq(n);
		for(int i=0; i<n; ++i){
			cin >> seq[i];
		}
		for(int i=0; i<n-k+1; ++i){
			int sum=0;
			for(int j=i;j<i+k;++j){
				sum+=seq[j];
			}
			maxi=max(sum,maxi);
		}
		cout << maxi << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

int a[1000000];

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

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
  bool flag=true;
  int n,k;
  cin>>n>>k;
  while(flag){
    vector<long long> a(n+1);
    a[0]=0;
    for(int i=0;i<n;i++){
      long long x;
      cin>>x;
      a[i+1]=a[i]+x;
    }
    long long ans=0;
    for(int i=0;i<=n-k;i++){
      ans=max(ans,a[k+i]-a[i]);
    }
    cout<<ans<<endl;
    cin>>n>>k;
    if(n==0&&k==0) flag=false;
  }
}

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

int main() {
    while(true) {
        int n,k; scanf("%d%d", &n, &k);
        if(n==0) break;
        static int a[100001];
        a[0] = 0;
        for(int i = 0; i < n; i++) {
            int x; scanf("%d", &x);
            a[i+1] = a[i] + x;
        }
        int max_sum = INT_MIN;
        for(int i = k; i <= n; i++) {
            max_sum = max(max_sum, a[i]-a[i-k]);
        }
        printf("%d\n", max_sum);
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;

int a[100000] = {};

signed main() {
	int k;
	int n;
	
	cin >> n >> k;
	while (n != 0 && k != 0) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		int m = -9999999999;
		int tmp = 0;
		int cnt = 0;

		for (int i = 0; i < n; i++) {
			if (i < k) {
				tmp += a[i];
			}
			else {
				tmp -= a[i - k];
				tmp += a[i];
				m = max(m, tmp);
			}
		}

		cout << m << endl;
	}
	return 0;
}