Go: package main

import "fmt"

func main() {

	for true {
		var n, k int
		fmt.Scan(&n, &k)

		if n == 0 && k == 0 {
			return
		}
		
		a := make([]int, n)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if i == 0 {
				ans[i] = a[i]
			} else {
				ans[i] = ans[i-1] + a[i]
			}
		}
		max := 0
		for i := k; i < n; i++ {
			t := ans[i] - ans[i-k]
			if max < t {
				max = t
			}
		}
		fmt.Println(max)
	}
}

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;
}

C++: while 1:
    n,k = [int(i) for i in input().split()]
    if not n and k:
        break
    a = [int(input()) for i in range(n)]
    b = [0]*len(a)

    for i in range(n):
        b[i] = b[i-1] + a[i]
    b = b + [0]

    c = [b[i + k - 1] - b[i - 1] for i in range(n - k + 1)]

    print(max(c))

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k,x;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i<n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        x=S[k];
        for(int l=1;l<n-k;l++){
            if(x<S[k+l]-S[l]){
                x=S[k+l]-S[l];
            }
        }
        cout << x << endl;
        cin >> n >> k;
        

    }

}