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 <vector>
#include <algorithm>
using namespace std;


int main(){
    int n, k;
    while (cin >> n >> k, n && k){
	vector<int> a;
	vector<int> s;

	int aa;
	for (int i = 0; i < n; i++){
	    cin >> aa;
	    a.push_back(aa);
	    s.push_back(0);
	}
	
	for (int i = 0; i < n - k; i++){
	    for (int j = i; j < i + k; j++){
		s[i] += a[j];
	    }
	}

	sort(s.begin(), s.end(), greater<int>());
	
	cout << s[0] << endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long int;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0)
      break;
    vector<int> as(n);
    for (auto &a : as)
      cin >> a;

    vector<int> sums(n + 1, 0);
    for (int i = 0; i < n; i++) {
      sums[i + 1] = sums[i] + as[i];
    }

    int ans = -1e9;
    for (int i = 0; i + k <= n; i++) {
      ans = max(ans, sums[i + k] - sums[i]);
    }

    cout << ans << endl;
  }

  return 0;
}

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

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
int ans=-2147483646;
int sum[100001];
for(int i=0;i<n;i++)
{
cin>>sum[i];
if(i!=0){sum[i]+=sum[i-1];}
if(i==m-1){ans=max(ans,sum[i]);}
else if(i>m-1){ans=max(ans,sum[i]-sum[i-m]);}
}
cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(){

	int n,k,a[100000],sum,ans,i;

	while(cin>>n>>k,n||k){

	sum=0;

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

	for(i=0;i<k;i++){
		sum=sum+a[i];
	}

    ans=sum;
    i=0;

    while(i<k&&(k+i)!=n){
    	sum=sum-a[i]+a[k+i];
    	ans=max(ans,sum);
    	i++;
    }

    cout<<ans<<endl;
	}
}

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

int num[100100];

int main(){
    int n,m;
    int sum=0;
    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 <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int loop,cas;

    while(cin>>loop>>cas)
    {
        int max=0,num[150000]={0};
        if(loop==0)break;
        for(int i=1;i<=loop;i++)
        {
            scanf("%d",&num[i]);
            if(i>=cas)
            {
                int now=0;
                for(int j=0;j<cas;j++)
                {
                    now+=num[i-j];
                    //printf("ok");
                }
                //cout<<now<<endl;
                if(max<now)max=now;
                //cout<<max<<endl;
            }
        }
        cout<<max<<endl;
    }
    return 0;
}

C++: #include<stdio.h>
int n[100001];
int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)return 0;
		int temp=0;
		for(int i=1;i<a+1;i++){
			int val;
			scanf("%d",&val);
			n[i]=(temp+=val);
			//printf("%d\n",n[i]);
		}
		int max=-1000000000;
		for(int i=0;i<a-b+1;i++){
			if(max<n[i+b]-n[i])max=n[i+b]-n[i];
			//printf("%d\n",n[i+b]-n[i]);
		}
		printf("%d\n",max);
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    vector<int>in(a);
    rep(i,a)cin>>in[i];
    int ma=0;
    rep(i,a-b+1){
      int sum=0;      
      loop(j,i,i+b)sum+=in[j];
      ma=max(ma,sum);
    }
    cout<<ma<<endl;
  }

}

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

#define MAX_BIT_SIZE 100001

int BIT[MAX_BIT_SIZE];
int n;

int sum(int index) {
    int ret = 0;

    while (index > 0) {
        ret += BIT[index];
        index -= index & -index;
    }

    return ret;
}

void add(int index, int value) {
    int i = 1;
    while (index <= n) {
        BIT[index] += value;
        index += i;
        i <<= 1;
    }
}

int main() {
    while (1) {
        int k;
        int i;
        int max_count = 0;


        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        memset(BIT, 0, MAX_BIT_SIZE);

        for (i=0;i<n;i++) {
            int d;
            scanf("%d", &d);
            add(i, d);
        }

        for (i=0;i<n-k;i++) {
            int now_count = sum(i+k) - sum(i);
            if (now_count > max_count)max_count = now_count;
        }

        printf("%d\n", max_count);
    }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n, k;
	int ans;
	while (true){
		int a[100001] = {}, b[100001] = {};
		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;
}