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<stdio.h>


int main(){
	
	int n,m;
	int input[100000];
	int cont;
	int now;
	int max;
	int i;
	
	while(1){
		
		scanf("%d%d",&n,&m);
		if(n==0 && m ==0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf("%d",&input[i]);
		}
		
		now = 0;
		
		for(i=0;i<m;i++){
			now += input[i];
		}
		max=now;
		
		cont = m;
		
		for(i=m;i<n;i++){
			now-=input[i-m];
			now+=input[i];
			
			if(now>max){
				max=now;
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<chrono>
#include<string>
#include<chrono>

using namespace std;






int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	






	
	
	//system("pause");
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,k,sum,max=0,i,j,a[100001];
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0) break;
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		for(i=1;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<bits/stdc++.h>
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  while(n!=0 || k!=0){

    vector<int> a(n);
    for(int i=0;i<n;i++){
      cin >> a.at(i);
    }

    vector<int> s(n);
    s.at(0) = 0;
    for(int i=1;i<n;i++){
      s.at(i) = s.at(i-1)+a.at(i-1);
    }

    int ans=0;
    for(int i=0;i<n-k;i++){
      ans = max(s.at(i+k)-s.at(i),ans);
    }

    cout << ans << endl;

    cin >> n >> k;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int n,k;
	int num[100001] = {0};
	while(scanf("%d%d",&n,&k),(n|k)){
		memset(num,0,sizeof(num));
		for(int i = 0; i < n; i++){
			scanf("%d",&num[i]);
		}
		int sum = 0;
		for(int i = 0; i < k; i++){
			sum += num[i];
		}
		for(int i = k; i < n; i++){
			int tmp = sum;
			tmp += num[i];
			tmp -= num[i-k];
			sum = max(sum,tmp);
		}
		printf("%d\n",sum);
	}
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int num[100005],ans,n,k,sum;
int main(){

    while(1){
    cin >> n >> k;
    if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
            cin >> num[i];
            if(k>i)sum+=num[i];
    }


    for(int i=k;i<n;i++){
        ans=max(ans,sum);
        //cout << "#" << sum << endl;
        sum-=num[i-k];
        sum+=num[i];
    }

    cout << ans << endl;
    }

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)
      return 0;

    int sum[n+1];
    sum[0] = 0;

    for (int i = 0; i < n; i++){
      int s;
      cin >> s;
      sum[i+1] = sum[i] + s;
    }

    int ans = -1987654321;

    for (int i = 0; i < n-k; i++){
      int tmp = sum[i+k] - sum[i];
      if(tmp > ans)
        ans = tmp;
    }

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

C++: #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)	return 0;
		int a[n];
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);;
		ll bgs=0;
		for(int i=0;i<=n-k;i++){
			ll temp=0;
			for(int j=0;j<k;j++)	temp+=a[i+j];
			bgs=max(bgs,temp);
		}
		printf("%lld\n",bgs);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    vector<int> ans(0);x
    while(1){
        cin>>n>>k;
        if(n==0&&k==0){
            break;
        }
        vector<int> vec(n);
        for(int i=0;i<n;i++){
            cin>>vec.at(i);
        }
        vector<int> rsw(n+1);
        rsw.at(0)=0;
        for(int i=1;i<n+1;i++){
            rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
        }
        ans.push_back(0);
        for(int i=k;i<n+1;i++){
            if(ans.at(ans.size()) < rsw.at(i) - rsw.at(i-k)){
                ans.at(ans.size()) = rsw.at(i) - rsw.at(i-k);
            }
        }
        cout << ans.at(ans.size()) << endl;
    }
    
}

C++: #include<cstdio>

int N,K;
int a[100000];


int main()
{
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++)scanf("%d",&a[i]);
    
    int sum=0;
    for(int i=0;i<K;i++)sum+=a[i];
    
    int ma=sum;
    for(int i=K;i<N;i++){
        sum-=a[i-K];
        sum+=a[i];
        ma=max(ma,sum);
    }
    printf("%d\n",ma);
    return 0;
}

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

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

        vector<int> s(N+1, 0);
        for(int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        ll res = -INF;
        for(int i = 0; i <= N-K; ++i) {
            ll val = s[K+i] - s[i];
            if(res < val) res = val;
        }
        cout << res << endl;
    }

}

C++: #include<stdio.h>
#include <iostream>
int length;
int k;
int* a;
//int sum;
int main(){
  while(1){
  std::cin>>length;
  std::cin>>k;
    if(k==0&&length==0)return 0;
  a=new int[length];
  for(int i=0;i<length;i++){
    int input=0;
    std::cin>>input;
    a[i]=input;
  }
  int* sums=new int[length];
  int s=0;
  for(int i=0;i<length;i++){
    s+=a[i];
    sums[i]=s;
  }
    //std::cout<<"\n";
  int max=0;
  int psum=0;
    int idx=0;
  for(int i=0;i<length-k;i++){
    int diff=sums[i+k]-sums[i];
    if(diff>max){
      max=diff;
      idx=i;
      
    //std::cout<<"\n";
    }
      //std::cout<<diff;
  }
  std::cout<<std::to_string(max)+"\n";
  //std::cout<<std::to_string(idx)+"\n";
  //std::cout<<s;
  }
  return 0;
}