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>
using namespace std;

int main(){
    int n,k;
    while(cin>>n>>k){
        int total[100010]={0},ip[100010]={0};
        if(n==0 && k==0)break;
        for(int i=0;i<n;i++){
            cin>>ip[i];
            if(i==k-1){
                for(int j=0;j<k;j++){
                    total[i]+=ip[i-j];
                }
            }
            if(i>k-1){
                total[i]=total[i-1]-ip[i-k]+ip[i];
            }
        }
        sort(total, total+n, greater<int>());
        cout<<total[0]<<endl;
    }
    return 0;
}

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

int main(){
	while(1){
		long n, k;
		long s[100001]; //i番目までの和
		s[0]=0;
		
		scanf(" %ld %ld", &n, &k);
		if(n==0) break;
		for(long i=0; i<n; ++i){
			int a;
			scanf(" %d", &a);
			s[i+1] = s[i]+a;
		}
		
		long max=-1500000000;
		for(int i=1; i+k<=n; ++i){
			long tmp=s[i+k]-s[i];	
			if(tmp>max) max=tmp;
		}
		
		printf("%ld\n", max);
	}
}

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 >> num;
      lists[n] = num;
    }
    for(int k = 0;k<numn-2;k++){
      outn = lists[k] + lists[k + 1] + lists[k + 2];
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << "";
  }
}

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

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

C++: #include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int N, K;
  while (cin >> N >> K) {
    if (N == 0) break;

    // 数列読み込み
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // 累積和を前計算
    vector<long long> s(N+1, 0);
    for (int i = 0; i < N; ++i) s[i + 1] = s[i] + a[i];

    long long res = -INF;
    for (int i = 0; i <= N - K; ++i) {
      long long val = s[K+i] - s[i];
      res = max(res, val);
    }

    cout << res << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,n2[100001],n_sum[100001];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>n2[i];
    }
    n_sum[0]=0;
    for(int i=1;i<=n;i++){
        n_sum[i]=n_sum[i-1]+n2[i-1];
    }
    int maxx=-10000001;
    for(int i=k-1;i<n;i++){
        int sum=0;
        sum=n_sum[i]-n_sum[i-k];
       // cout<<sum<<endl;
        maxx=max(maxx,sum);
    }
    cout<<maxx<<endl;
   // for(int i=0;i<=n;i++){
      //  cout<<n_sum[i]<<endl;
   // }
}

C++: #include <iostream>
#include <vector>
using namespace std;
const long INF = 1L<<60;

int main() {
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        vector<int> s(N+1, 0);
        for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        long res = -INF;
        for (int i = 0; i <= N-K; ++i) {
            long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0516 : Maximum Sum **/
int main()
{
	int N, K;
	while (cin>>N>>K, N||K) {
		vector<int> a(N);
		rep(i, N) cin>>a[i];
	
		int k=0;
		rep(i, K) k+=a[i];
		
		int ans=k;
		REP(i, K, N) {
			k+=a[i] - a[i-K];
			ans = max(ans, k);
		}
		cout << ans << endl;
	}
}

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

int a[200000];
int n,l,s,maxn;;

int main(){
    while(true){
        cin>>n>>l;
        if(n==0 && l==0){break;}
        for(int i=0;i<n;i++){
            cin>>a[i];
            if(i<l){s+=a[i];}
        }
        maxn=s;
        for(int i=0;i<n-l;i++){
            s-=a[i];
            s+=a[i+l];
            maxn=max(s,maxn);
        }
        cout<<maxn<<endl;
    }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
  cin >> n >> k;
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    cin >> set[i];
  }

  for(int i=1;i<n-1;i++){
    if(set[i-1]+set[i]+set[i+1]>max || i==1) max=set[i-1]+set[i]+set[i+1];
  }
  cout << max << endl;
  }
}

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

using namespace std;

int main(){


    int n,k,ans=0,ans2;
    while(1){
    scanf("%d%d",&n,&k);
    if(n==0&&k==0)break;
    int num[n];
    for(int y=0;y<n;y++){
        scanf("%d",&num[y]);
    if(y>=k){
        for(int a=0;a<k;a++){
        ans+=num[y-k+a];
        }
        if(ans2<ans){
            ans2=ans;
        }
        ans=0;
    }}
    printf("%d\n",ans2);
    }

return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	while (1) {
		int n, k, a[100005] = { 0 }, sum[100005] = { 0 };
		long long m = -9999999999;
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < k; i++) {
			sum[0] += a[i];
		}
		for (int i = 1; i < n - 2; i++) {
			sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
		}
		for (int i = 0; i < n - 2; i++) {
			if (m < sum[i]) {
				m = sum[i];
			}
		}
		cout << m << endl;
	}
}

C++: #include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,a[100000],ans=0,sum=0;
    while(cin>>n>>k,n||k){
    ans=0,sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        if(i>=k)
            sum-=a[i-k];
        if(i>=k-1)
            ans=max(ans,sum);
    }
    cout<<ans<<endl;}
}