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 <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  const lint inf=1LL<<60;
  bool is=true;
  lint n,k;cin>>n>>k;
  int count=0;
  vector<int> r;
  while(is){
    if(n==0&&k==0) break;
    lint a[101000],s[101000];
    rep(i,n){
      cin>>a[i];
    }
    s[0]=0;
    rep(i,n){
      s[i+1]=s[i]+a[i];
    }
    lint result=-inf;
    for(int i=0;i<=n-k;i++){
      lint sum=s[k+i]-s[i];
      if(result<sum) result=sum;
    }
    r.pb(result);
    cin>>n>>k;
  }
  for(int i=0;i<r.size();i++){
    cout<<r[i]<<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>
using namespace std;
int num[100100];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<100100;i++)num[i]=0;
         cin>>n>>m;
         if(n==0&&m==0)break;
         for(int i=0;i<n;i++) cin>>num[i];
         for(int i=0;i<n-m;i++){
              int min=num[i]+num[i+1]+num[i+2];
              if(ans<min)ans=min;
         }
         cout<<ans<<endl;
         ans=0;
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int n,a[100000001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int inp[1000000];
	
int main() {
	int n,m;
	while(n=in(),m=in()){
		int i;
		for(i=0;i<n;i++){
			inp[i]=in();
		}
		Int max=-2000000000;
		for(i=0;i<=n-m;i++){
			Int sum=0;
			int k;
			for(k=0;k<m;k++){
				sum+=inp[i+k];
				//cout<<sum<<endl;
			}
			if(max<sum)max=sum;
		}
		cout<<max;
	}
	return 0;
}

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

long long int sum,k,n,num[200000];

int main(){
    long long int ans=-10000000000000;
    cin >> n >> k;

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

    for(int i=0;i<n-k;i++){
        for(int j=i;j<i+k;j++){
            sum+=num[j];
        }
        if(ans<sum)ans=sum;
        sum=0;
    }

    cout << ans ;

return 0;
}

C++: #include<stdio.h>

//更新書き換え型
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;
	scanf("%d%d",&n,&k);
	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(){
int n,k,s,ans;
int a[100001];
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<n-k+1;i++){
s=0;
for(int j=i;j<i+k;j++)s+=a[j];
if(i==0)ans=s;
if(s>ans)ans=s;}
cout<<ans<<endl;}}

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

int main(){

	for(int se = 0; se<5; se++){

		int n,k,B[100001],t = -999999;
		cin >> n >> k;

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

		B[0] = 0;
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			B[i+1] = B[i] + a;
		}
		for(int i = 1; i+k-1<n; i++){
			t = max(B[i+k-1]-B[i-1],t);
		}
		cout << t << endl;
	}
	return 0;
}

C++: #include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<set>
#include<string>
using namespace std;
int main(){
    int n,k,ma;
    for(;;){
        int num[100001]={0};
        cin>>n>>k;
        if(n==0&&k==0)break;
        for(int i=0;i<n;i++){
            cin>>num[i];
        }
        for(int i=0;i<n-k;i++){
            int all=0;
            for(int j=0;j<k;j++){
                all+=num[i+j];
            }
        if(i==0)ma=all;
        ma=max(ma,all);
        }
        cout<<ma<<endl;
    }
}

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;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int gomi;
  cin >> gomi >> gomi;
  int ans = 0;
  for(int i = 0; i < k; i++) {
    ans += a[i];
  }
  int mx = ans;
  for(int i = 0; i < n - k; i++) {
    mx = mx + a[k + i] - a[i];
    ans = max(mx, ans);
  }

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

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

long long int sum,k,n,num[200000];

int main(){
    long long int ans=-1000000000;
    cin >> n >> k;

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

    for(int i=0;i<n-k;i++){
        for(int j=i;j<i+k;j++){
            sum+=num[j];
        }
        if(ans<sum)ans=sum;
        sum=0;
    }

    cout << ans << endl;

return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(n==0)	return 0;
		int a[n];
		for(int i=0;i<n;i++)	cin>>a[i];
		ll bgs=0;
		for(int i=0;i<=n-k;i++){
			ll temp=0;
			for(int j=0;j<k;j++)	temp+=a[i+j];
			bgs=max(bgs,temp);
		}
		cout<<bgs<<endl;
	}
}