Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<stdio.h>

using namespace std;

int main(){


    int n,k,ans=0,ans2=0,mx=0;
    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]);
    }
        for(int a=0;a<k;a++){
        ans+=num[a];
        }
        mx=ans;
    for(int j=0;j<n-k;j++){
        ans2=ans-num[j]+num[j+k];
        if(mx<ans2){
            mx=ans2;
        }
    ans=ans2;
    ans2=0;
    }
    printf("%d\n",mx);
    }

return 0;
}

C++: #include <stdio.h>
int main(){
    long long int n,k,a[10],top;
    while(1){
        scanf("%lld%lld",&n,&k);
        if(n==0)return 0;
        scanf("%lld",&a[0]);
        for(int i=1;i<k;i++){
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
        }
        top=a[k-1];
        for(int i=k;i<n;i++){
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
            a[i]-=a[i-k];
            if(i!=k)a[i]+=a[i-k-1];
            if(a[i]>top)top=a[i];
        }
        printf("%lld\n",top);
    }
}

C++: #include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
    while(true) {
        int n, k;
        cin >> n >> k;
        int sum = 0;
        int ans = 0;
        queue<int> q;
        for(int i = 0; i < n; ++i) {
            int num;
            cin >> num;

            sum += num;
            if(i == k-1) ans = sum;
            if(i >= k) {
                sum -= q.front();
                q.pop();
                ans = max(ans, sum);
            }
            q.push(num);
        }

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

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

long long int num[100100];

int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=0;
    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];
        }
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        cout<<ans<<endl;
        ans=0;
        }
    return 0;
}

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

#include<algorithm>

int a[100001];

int main() {
	int n, k;
	while (cin >> n >> k && n != 0 && k != 0) {
		a[0] = 0;
		for (int i = 1; i <= n; ++i) {
			cin >> a[i];
			a[i] += a[i - 1];
		}
		int maxi = 0;
		for (int i = k; i <= n; ++i) {
			maxi = max(maxi, a[i] - a[i - k]);
		}

		cout << maxi << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	while(1){
        int n,k;
        int ans[10010] = {0};
        cin >> n;
        cin >> k;
        if(n == 0 && k == 0) break;
        for(int i = 0; i < n; i++){
            cin >> ans[i];
        }
        int mx = 0,sum = 0;
        for(int i = 0; i < k; i++){
            sum += ans[i];
        }
        mx = sum;
        for(int i = k; i < n; i++){
            sum += ans[i];
            sum -= ans[i-k];
            mx = max(mx,sum);
        }
        cout << mx << endl;
	}
	return 0;
}

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


main() {
  while(1) {
    int n, k;
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    int buf[k];
    int pb = 0;
    fill_n(buf, k, 0);
    int maxS = -INF;
    int sum = 0;
    for(int i = 0; i < n; i++) {
      sum -= buf[pb];
      cin >> buf[pb];
      sum += buf[pb];
      pb = (pb+1)%k;
      if(i+1 < k) continue;
      if(maxS == -INF || sum > maxS) maxS = sum;
    }
    cout << maxS << endl;
  }
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;while (1) {scanf("%d %d",&N,&K);if (!N || N==EOF) return 0;ans=-1000000007;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);}}

C++: #include <iostream>
using namespace std;
int main(){
  int n,m;
  int k[100001];
  while( cin >> n >> m , n+m ){
    int sum = 0;
    for(int i = 0 ; i < n ; i++ )cin >> k[i];
    for(int i = 0 ; i < m ; i++ )sum+=k[i]; 

    int mx = 0;

    for(int i = 0 ; m < n ; m++,i++){
      sum += k[m]-k[i];
      mx = max(mx,sum);
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    int c[a],w=0;
    r(i,a)cin>>c[i];
    r(i,a-b){
      int cc=0;
      for(int j=i;j<i+b;j++)cc+=c[j];
      w=max(w,cc);
    }
    cout<<w<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k; cin >> n >> k;
	vector<LL> sums(n);
	rep(i, n)
	{
		cin >> sums[i];
		if (i != 0)
			sums[i] += sums[i - 1];
	}
	LL ans = -10000000000;
	ans = *max_element(sums.begin(), sums.begin() + k);
	for (int i = 1; i + k < n; i++)
	{
		ans = max(ans, sums[i + k - 1] - sums[i - 1]);
	}
	cout << ans << 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;
            if(i<k){
            sum+=num;
            box[i]=num;
        }
        else if(i>=k){
            if(sum-box[0]+num>ans)ans=sum-box[0]+num;
            sum+=num-box[0];
            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>
using namespace std;

int main(){
    int n,k;
    
    while(1){
        cin >> n >> k;
        int N[n],sum[n-k+1];
        if(n==0 && k==0) break;
        for(int i=0; i<n-k+1; i++){
            sum[i] = 0;
        }
        
        for(int i=0; i<n; i++){
            cin >> N[i];
        }
        for(int i=0; i<=n-k; i++){
            for(int j=0; j<k; j++){
                sum[i] += N[i+j];
            }
        }
        int max = 0;
        for(int i=0; i<n; i++){
            if(max < sum[i]){
                max = sum[i];
            }
        }
        cout << max << endl;
    }
}