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 <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n, k;
	while(cin >> n >> k, n || k)
	{
		int max = 0;
		int sum = 0;
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		for(int i = 0; i < k; ++i)
		{
			sum += Vec[i];
		}
		if(max < sum)
		{
			max = sum;
		}
		for(int i = 1; i + k - 1 < n; ++i)
		{
			sum -= Vec[i - 1];
			sum += Vec[i + k - 1];
			if(max < sum)
			{
				max = sum;
			}	
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa )
{
	int temp = 0;
	int i;
	/*
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	*/
	temp += wa + suretu[cont+k-1];
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0));
	}
}

C++: #include <stdio.h>
int array[5000],n,k,max;

void func(int now){
	int i,j,temp=0;
	
	if(now==n-k)return;
	
	for(i=now;i<now+k;i++){
		temp+=array[i];
	}
	if(temp>max)max=temp;
	func(now+1);
}
		
		


int main(void){
	int i;
	
	while(scanf("%d",&n),n){
		max=0;
		
		scanf("%d",&k);
		for(i=0;i<n;i++){
			scanf("%d",&array[i]);
		}
		func(0);
		
		printf("%d\n",max);
		
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

#define MAX 100000

int main(){

	int n,k,a[MAX];
	long long num,max;

	while(1){

		cin>>n>>k;
		if(n==0&&k==0) break;

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

		num=0;
		for(int j=0;j<k;j++){
			num+=a[j];
		}
		max=num;

		for(int i=0;i<n-k;i++){
			num-=a[i];
			num+=a[i+k];
			max=(max<num)?num:max;
		}
		
		cout<<max<<endl;
		
	}

	return 0;
}

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

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[100000];
	for(int i=0;i<100000;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;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

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

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

using namespace std;

int main(){

	int n,k,a[100000],sum,ans,i;

	while(cin>>n>>k,n||k){

	sum=0;

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

	for(i=0;i<k;i++){
		sum=sum+a[i];
	}

    ans=sum;
    i=0;

    for(i=k;i<n;i++){
    	sum=sum-a[i-k]+a[i];
    	ans=max(ans,sum);
    }

    cout<<ans<<endl;
	}
}

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

int main(){
	int n,k,i,j,l;
	int a[100000];
	int Smax,S;
	while(l<5){
		cin>>n;
		cin>>k;
		if(n==0){break;}
		
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		for(i=0;i<n-k;i++){
			S=0;
			for(j=i;j<i+k;j++){
				S+=a[j];
			}
			if(Smax<S){Smax=S;}
		}
		
		cout<<Smax<<endl;
		
		l++;
	}
		return 0;
		
}

C++: #include <stdio.h>
int main(){
	int n,k,i,max=0;
	int x[100001];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)[
	scanf("%d",&x[i]);
}
for(i=0;i<k;i++){
	max+=x[i];
}
	for(i=0;i<n-k;i++){
		if(x[i]<x[i+k]){
			max-=x[i];
			max+=x[i+k];
		}}
		printf("%d\n",max);
		return 0;
		}

C++: #include<bits/stdc++.h>
using namespace std;
int N,K;
int a[100000];


int main()
{
    while(scanf("%d%d",&N,&K),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 <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    while(cin >> n >> k and n and k) {
        vector<int> a(n + 1);
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int ans = lim<int>::min();
        int s = 0;
        for(int i = 1; i <= n; i++) {
            s += a[i];
            if(i >= k) {
                s -= a[i - k];
                ans = max(ans, s);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

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

C++: #include<cstdio>

int main()
{
    int n,m,a[100008];
    while(~scanf("%d%d",&n,&m))
    {
        if(!n&&!m) break;
        int sum = 0,cap = 0,temp = -2000000001;
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        for(int i=0;i<n;i++){
            if(cap!=m){ sum += a[i]; cap++; }
            else sum += a[i]-a[i-3];
            if(sum>temp) temp=sum;
        }
        printf("%d\n",temp);
    }
    return 0;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	while (true) {
		int n, k;
		cin >> n >> k;
		if (n == k&&k == 0) {
			return 0;
		}
		vector<int> a;
		REP(i, n) {
			int b;
			cin >> b;
			a.push_back(b);
		}
		long long ans = -1000000000000;
		long long tmp = 0;
		for (int i = 0;i < k;++i) {
			tmp += a[i];
		}
		ans = tmp;
		for (int i = k;i < n;++i) {
			tmp += a[i];
			tmp -= a[i - k];
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}
}