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<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
int a[MAXN], sum[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    while (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; i++) 
    		sum[i+1] = sum[i]+a[i];
    	int ans = -1e9-1;
    	for (int i = 0; i+K <= N; i++) {
    		ans = max(ans, sum[i+K]-sum[i]);
    	}
    	cout << ans << endl;
    }
    return 0;
}

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

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

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

int s[100000 + 1];

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

		for (int i = 0; i < n - k; i++) {
			int t = 0;
			for (int j = 0; j < k; j++) {
				t+=s[i+j];
			}
			ans = max(ans, t);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
int n,k;
int main(void){
  scanf("%d%d",&n,&k);
  while(n!=0){
    int i;
    int mem[100000]={0};
    for(i=0;i<n;i++){
      scanf("%d",&(mem[i]));
    }
    int ans=0;
    int now=0;
    for(i=0;i<k;i++){
      now+=mem[i];
      ans=now;
    }
    for(i=0;i+k<n;i++){
      now-=mem[i];
      now+=mem[i+k];
      ans=(ans<now)?now:ans;
    }
    printf("%d\n",ans);
    scanf("%d%d",&n,&k);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <numeric>
using namespace std;
int main(){
  int n, k, l;
  int N[100001], ans, sum, tmp;
  while(cin >> n >> k, n && k){
    ans = 0, sum = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }

    for(l = 0 ; l < k ; l++){
      sum += N[l];
    }
    ans = max(ans, sum);
    cout << ans << endl;
    for(int i = l ; i < n ; i++){
      sum += N[i];
      sum -= N[i-k];
      tmp = sum;
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

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

constexpr int MAX_N= 100000;

int n,k;
int sums[MAX_N];

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

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int n,k;
    while (cin >> n >> k) 
    {
        if (n == 0 && k==0) 
        {
            break;
        }
        vector<int> vec(n);
        vector<int> sum(n -k +1);
        int input;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];//input;
            //vec.push_back(input);
        }
        for (int i = 0; i < n - k + 1; i++) 
        {
            sum[i]=0;
            for (int j = 0; j < k; j++) 
            {
                sum[i] += vec[i + j];
                //cout << " " << vec[i+j] << endl;
            }
            //cout << "sum="<< sum[i] << endl;
        }
        //for (int i = 0; i < n-k+1; i++) 
        //{
        //    cout << vec[i]<<endl;
        //}
        sort(sum.begin(), sum.end() , greater<int>() );
        //for (int i = 0; i < n-k+1; i++) 
        //{
        //    cout << vec[i]<<endl;
        //}
        cout << sum[0];
    }
    return 0;
}

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

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

C++: #include<cstdio>
#include<math.h>
#include<algorithm>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
int N,K;
int A[100002];


int main(){
	while(1){
	scanf("%d %d",&N,&K);
	if(N==0&&K==0)break;
	rep(i,N)scanf("%d",&A[i]);
	long long int ans=0;
	long long int sans=0;
	rep(i,K)sans+=A[i];
	ans=sans;
	rep(i,N-K){
		sans-=A[i];
		sans+=A[i+K];
		ans=max(ans,sans);
	}
	printf("%lld\n",ans);
	}
}

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

using namespace std;

typedef long long ll;

ll solve(int n, int k) {
    ll a[n+1];
    a[0] = 0;
    for(int i=1;i<=n;++i){
        cin >> a[i];
        a[i] += a[i-1];
    }

    ll ans = 0LL;
    for(int i=1;i<=n-k;++i) {
        ans = max(ans, a[i+k-1]-a[i-1]);
    }
    return ans;
}

int main() {
    int n, k;

    while(cin >> n >> k && n) {
        cout << solve(n, k) << endl;
    }
}

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

    }
    return 0;
}

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

int main(){
    int n, k;
    while(cin >>n >>k){
        if(n == 0 && k == 0) break;
        vector<int> vec;
        int max = 0, now = 0;
        for(int i = 0; i < k; i++){
            int tmp;
            cin >>tmp;
            max += tmp;
            now += tmp;
            vec.push_back(tmp);
        }
        for(int i = k; i < n; i++){
            int tmp;
            cin >>tmp;
            vec.push_back(tmp);
            now += tmp;
            now -= vec[i - k];
            if(max < now) max = now;
        }
        cout <<max <<endl;
    }
    return 0;
}