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>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<i)*a[i++-k],k<i&M<s&&(M=s))std::cin>>a[i];}

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

using namespace std;

int main(void){
    int i,n,k,a[100100],ans;
    cin >> n >> k;
    while(n!=0 && k!=0){
        ans = 0;
        a[0] = 0;
        for(i=1; i<=n; i++){
            cin >> a[i];
            a[i] += a[i-1];
        }
        for(i=k; i<=n; i++){
            ans = max(ans,a[i]-a[i-k]);
        }
        cout << ans << endl;
        cin >> n >> k;
    }
    return 0;
}

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

int main(){
	int a[10000];
	int n, k;
	int sum = 0;
	int m = 0;
	
	for(;;){
		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; i++){
			sum = 0;
			for(int j = i; j < i+k; j++){
				sum += a[j];
			}
			m = max(m, sum);
		}
		
		cout << m << endl;
	}
	
	return 0;
}

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

using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
	int cnt,n,m,dat[110000];
	while(1){
	cin>>n>>m;
	if(n==0 && m==0){
		break;
	}
	for(int i=0;i<n;i++){
		cin>>dat[i];
	}
	int ans=0;
	int cnt=0;
	for(int i=0;i<m;i++){
		ans+=dat[i];
	}
	cnt=ans;
	for(int i=m;i<n;i++){
		cnt+=dat[i]-dat[i-m];
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>


using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;

int main(){

	int n,k;
	int a[100001];


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

	int ub,lb;
	ub=lb=0;
	ll cSum=0;
	for(int i = 0; i < k; i++){
		cSum += a[i];
	}
	ll maxSum = cSum;
	for(int i = 1; i <= n - k; i++){
		cSum -= a[i-1];
		cSum += a[i+k-1];
		maxSum = max(maxSum,cSum);
	}

	cout << maxSum << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    int n, m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) {
            break;
        }
        int nums[n];
        for(int i = 0; i < n; i++) {
            cin >> nums[i];
            if(i != 0) {
                nums[i] += nums[i - 1];
            }
        }

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

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

using namespace std;

int rsw[1000002];

int main() {
	int n, k;
	while (cin >> n >> k, n + k) {
		rsw[0] = 0;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			rsw[i + 1] = rsw[i] + a;
		}
		int MAX = rsw[k] - rsw[0];
		for (int i = 0; i < n - k + 1; i++) {
			MAX = max(MAX, rsw[i + k] - rsw[i]);
		}
		cout << MAX << endl;
		for (int i = 0; i < 1000002; i++) {
			rsw[i] = 0;
		}
	}
	return 0;
}

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

int main(){
  int n,k,x;
  vector<int> s;
  int start,end,ans=0,sum;
  
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>x;
    s.push_back(x);
  }
  
  start=0;end=k;
  while(end-1<n){
    sum=0;
    for(int i=start;i<end;i++){
      sum+=s[i];
    }
    ans=max(ans,sum);
    
    start++;end++;
  }
  
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;

int main(void)
{
	int n, k, s, b;
	int a[100001], m[100001];
	while (1)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		for (int i = 0;i < n;i++)
			cin >> a[i];

		m[0] = a[0];
		for (int i = 0;i < n;i++)
			m[i + 1] = m[i] + a[i];

		s = m[k] - m[0];
		for (int i = 0;i < n - k + 1;i++)
		{
			b = m[i + k + 1] - m[i + 1];
			if (s < b) 
				s = b;

		}

	}
	cout << s << endl;
	return 0;
}

C++: #include <iostream>
template <typename T>
class RingBuffer {
	int size;
	int idx;
	T* arr;
	T& at(int i) {
		return arr[i % size];
	}
public:
	RingBuffer(int s) {
		size = s;
		idx = 0;
		arr = new T[s];
	}
	void push(T t) {
		at(idx++) = t;
	}
	const T& peek() {
		return at(idx);
	}
};
int solve(int n, int k) {
	RingBuffer<int> buffer(k);
	int sum = 0;
	int a;
	for (auto i = 0; i < k; ++i) {
		std::cin >> a;
		buffer.push(a);
		sum += a;
	}
	int max = sum;
	for (auto i = k; i < n; ++i) {
		std::cin >> a;
		sum += a - buffer.peek();
		buffer.push(a);
		if (sum > max) max = sum;
	}
	return max;
}
int main() {
	int n, k;
	while (std::cin >> n >> k && n != 0) {
		std::cout << solve(n, k) << '\n';
	}
	return 0;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    while(n !=0 && k !=0){
        int a;
        int s[100010];
        s[0]=0;
        for(int i=0;i<n;i++){
            cin >> a;
            s[i+1]=s[i]+a;
        }
        int m=0;
        for(int i=0;i<n-k;i++){ 
            if(m < s[i+k]-s[i]){
                m = s[i+k]-s[i];
            }
        }
        cout << m << endl;
        cin >> n >> k;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int ans=0,n,k,box[10000]={0},sum=0;;
        cin >> n >> k;
        if(n==0&&k==0)break;
        for(int i=0;i<k;i++){
            cin >> box[i];
            sum+=box[i];
            }
            ans=sum;
          for(int i=k;i<n;i++){
                cin >> box[i];
                if(n-k==0)break;
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;
    }
    return 0;
}

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

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[199999];
	for(int i=0;i<199999;i++) wa[i] = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		for(int j=0;j<k;j++){
			wa[i+j] += x;
		}
	}
	cin >> x >> x;
	for(int i=k-1;i<n;i++){
		if(maxnum < wa[i]) maxnum = wa[i];
	}
	cout << maxnum << endl;
}