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<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  while(true){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n==0&&k==0) return 0;
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    int sum = 0,ans = 0;
    for(int i=0;i+k<=n;i++){
      if(i==0){
        for(int j=0;j<k;j++) sum += a[i+j];
        ans = sum;
      }else{
        sum = sum - a[i-1] + a[i+k-1];
        ans = max(ans,sum);
      }
    }
    printf("%d\n",ans);
  }
}

C++: #include<stdio.h>
int main(void){
	int n,k,a[100000],i,j,sum,max;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)break;
		for(i=0;i<n;i++) scanf("%d",&a[i]);
		max=-1;
		for(i=0;i<n;i++){
			sum=0;
			if(i+k<n){
				for(j=i;j<i+k;j++) sum+=a[j];
			}
			if(max<sum) max=sum;
		}
		printf("%d\n",max);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n, k, a[100001];
    int pre = 0;
    int max = 0;

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

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

    for (int i = 1; i <= n-k; i++) {
        pre = pre - a[i-1] + a[i+k-1];
        if (pre > max) {
            max = pre;
        }
    }

    cout << max << endl;
    cin >> n >> k;
    max = 0;
    pre = 0;
    }
}

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

using namespace std;

int n, k ,i = 0, a[100000];
long long int b[100000];
long long int result[100][2];

int main()
{
	for (;; i++)
	{
		cin >> n >> k;
		if (n == 0)
		{
			break;
		}

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

		for (int p = 0; p < n - k; p++)
		{
			for (int q = 0; q < k; q++)
			{
				result[i][0] += a[p + q];
			}
			result[i][1] = max(result[i][0], result[i][1]);
			result[i][0] = 0;
		}
	}
	for (int p = 0; p < i; p++)
	{
		cout << result[p][1] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

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

        vector<int> cs(n+1, 0);
        for(int i = 1; i < n+1; i++) {
            cs[i] = cs[i-1];
            cs[i] += a[i-1];
        }

        int ans = (-1) * INF;
        for(int i = 0; i < n+1-k; i++) {
            ans = max(ans, cs[i+k] - cs[i]);
        }
        cout << ans << endl;
    }

}

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

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

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

using namespace std;

int main(){
	int n,k,sum=0,max;
	int a[100000];
	while(scanf("%d %d",&n,&k)){
		if(n==0&&k==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<n;i++){
			if(i<k)
			sum+=a[i];
			else if(i>=k){
				sum+=a[i];
				sum-=a[i-k];
			}
			if(i==k-1)
			max=sum;
			else if(i>k-1){
				max=(max<sum ? sum:max);
			}
		}
		printf("%d\n",max);
	}
}

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

int main() {
	int n, k, a[100000], i, S[100000], m=0;
	cin >> n >> k;
	for (i = 0; i<n; i++) {
		cin >> a[i];
	}
	S[0] = 0;
	for (i = 0; i < k; i++) {
		S[0] += a[i];
	}
	for (i = 1; i<n - k + 1; i++) {
		S[i] = S[i - 1] - a[i - 1] + a[i + k-1];
		m = max(m, S[i]);
	}
	cout << m << endl;
}

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

int main(void){
  int n , k;
  while(cin>>n>>k,n+k){
  vector<int> in(n,0);
  for(int i = 0 ; i < in.size() ; i ++) 
    cin>>in[i];
  int res = 0;
  for(int i = 0 ; i < in.size() - k ; i ++){
    int sum = 0;
    for(int j = i ; j < i + k ; j ++){
      sum += in[j]; 
    }
    res = max(res,sum);
  }
  
  cout<<res<<endl;
  }
}