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++: import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			final int n = in.nextInt();
			final int k = in.nextInt();
			if (n == 0 && k == 0) { throw new RuntimeException(); }
			int max = Integer.MIN_VALUE, val = 0;
			Deque<Integer> deq = new ArrayDeque<Integer>(k);
			for (int i = 0; i < n; i++) {
				final int number = in.nextInt();
				if (i < k) {
					val += number;
				} else {
					final int f = deq.poll();
					val += (number - f);
				}
				deq.addLast(number);
				if (val > max) {
					max = val;
				}
			}
			System.out.println(max);
		}
	}
}

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

int main(){
while(1){
	int a[100000+2],n,k,ans=0,sum=0;
	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<k;i++){
		sum+=a[i];
	}
	ans=sum;
	for(int i=k;i<n;i++){
		sum+=a[i]-a[i-k];
		if(ans<sum)ans=sum;
	}
	printf("%d\n",ans);
}
}

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

using namespace std;

int a[100000];

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

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(i-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 sum(int S[], int begin, int end) {
    int ans = 0;
    for (int i = begin; i < end; ++i) {
        ans += S[i];
    }
    return ans;
}

int main() {

    int n, k;
    for (;;) {
        cin >> n >> k;
        if (n == 0 && k == 0) break;

        int S[100000] = {0};
        for (int i = 0; i < n; ++i) {
            cin >> S[i];
        }

        int dummy = sum(S, 0, k);
        int m = n - k + 1;
        int tmp = 0;
        int ans = dummy;
        for (int i = 1; i < m; ++i) {
            int tmp = dummy - S[i - 1] + S[i + k - 1];
            dummy = tmp;
            if (ans < tmp) ans = tmp;
        }

        cout << ans << endl;
    }

    return 0;
}

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

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

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

int main(){
	int n,k;
	while(cin>>n>>k,n||k){
		queue<int> q;
		int t,sum=0,ans= -10000*100000;
		for(int i=0;i<k;i++){
			cin>>t;
			sum += t;
			q.push(t);
		}
		ans=max(ans,sum);
		for(int i=0;i<n-k;i++){
			t=q.front();
			q.pop();
			sum -= t;
			cin>>t;
			sum += t;
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
	int n, k;
	while (cin >> n >> k, n, k) {

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

		int s[10000] = {};
		for (int i = 0;i <= n - k;i++) {
			for (int j = 0;j < k;j++) {
				s[i] += a[i + j];
			}
		}
		sort(s, s + n - k + 1);
		cout << s[n - k] << endl;
	}
	return 0;
}

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

int main(){
	while(true) {
		int n;
		int k;
		cin >> n >> k;
		if ( n == 0 ) break;
		vector<int> a;
		int c;
		for ( int i = 0; i < n ; i++ ) {
			cin >> c;
			a.push_back(c);
		}
		c = 0;
		for ( int i = 0; i < k; i++ ) {
			c += a[i];
		}
		int s = c;
		for ( int i = 0; i < n - k; i++ ) {
			c -= a[i];
			c += a[i+k];
			s = max(s,c);
		}
		cout << s << endl;
	}
	return 0;
}

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

int main() {
	int n, m;
	while(cin >> n >> m, n||m) {
		vector<int> a;
		int tmp;
		for (int i=0; i<n; i++) {
			cin >> tmp;
			a.push_back(tmp);
		}
		int max = -1e30;
		for (int i=0; i<=a.size()-m; i++) {
			tmp = 0;
			for (int j=0; j<m; j++) {
				tmp += a[i+j];
			}
			if (tmp > max) max = tmp;
		}
		cout << max << endl;
	}
	return 0;
}

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

int main(){
    int n,k;
    while(cin>>n>>k,n||k){
        int dp[100001]={},series[100001],sum,edge,ans=0;
        for(int i=1;i<=n;i++){
            cin>>series[i];
        }
        for(int i=1;i<k;i++){
            dp[0]+=series[i];
        }
        for(int i=1;i<=n-k+1;i++){
            edge=i+k-1;
            if(ans<dp[i-1]+series[edge]) ans = dp[i-1]+series[edge];
            dp[i] = dp[i-1]+series[edge]-series[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	int n, m;
	for (; cin >> n >> m;)
	{
		if (n == 0 && m == 0)
		{
			break;
		}

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

		int maxs = -1 << 31;

		for (int i = 0; i < n - m; i++)
		{
			int sum = accumulate(a.begin() + i, a.begin() + i + m, 0);
			maxs = max(maxs, sum);
		}

		cout << maxs << endl;
	}
}

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[i];
    vector<int> S(n+1);
    S[0] = 0;
    for(int i=0;i<=n;i++){
        S[i] = S[i-1] + a[i-1];
    }
    int max = 0;
    int tmp = 0;
    for(int i= 0;i<=n-k;i++){
        tmp= S[i+k] - S[i];
        if(max<tmp){
            max = tmp;
        }
    }
    cout<<max<<endl;
    cin>>n>>k;
    }
    return 0;
}

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

int64_t	calc_partial_sum(int n, int k, const vector<int> &a_vec)
{
	int64_t	s = 0;
	int64_t	max_s = 0;
	for (int i = 0; i < k; ++i)
		s += a_vec.at(i);
	max_s = s;
	for (int i = k; i < n; ++i) {
		s += a_vec.at(i) - a_vec.at(i - k);
		if (max_s < s)
			max_s = s;
	}
	return max_s;
}

int	main()
{
	int	n, k;
	while (cin >> n >> k) {
		if (n == 0 && k == 0)
			break;
		vector<int>	a_vec(n);
		for (int i = 0; i < n; ++i)
			cin >> a_vec.at(i);
		cout << calc_partial_sum(n, k, a_vec) << endl;
	}
}