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;
#define MAX 100001
int main(void){
  int n , k;
  while(cin>>n>>k,n+k){
  int in[MAX];
  int dp[MAX];
  for(int i = 0 ; i < n ; i ++) 
    cin>>in[i];
  for(int i = 1 ; i < n ; i ++){
    dp[i] = in[i - 1] + in[i];
  }
  int res = -(1<<22);
  for(int i = 2 ; i < n ; i ++){
    res = max(res,in[i] + dp[i - 1]);
    //cout<<in[i] <<" " << dp[i - 1] << endl;
  }
  
  
  cout<<res<<endl;
  }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n,k;cin>>n>>k,n|k;){
		vi a(n);
		rep(i,n)
			cin>>a[i];
		
		int sum=accumulate(a.begin(),a.begin()+k,0);
		int res=sum;
		repi(i,k,n){
			sum=sum+a[i]-a[i-k];
			res=max(res,sum);
		}
		cout<<res<<endl;
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

LL S[MAX_N+1],n,m;
LL ans;

class BIT{
    public:
        int N;
        void init(int _N){
            N=_N;
            rep(i,N+1)S[i]=0;
        }

        LL getSum(int i){
            LL s=0;
            while(i){
                s+=S[i];
                i-=i&-i;
            }
            return s;
        }

        void add(int i,int x){
            while(i<=N){
                S[i]+=x;
                i+=i&-i;
            }
        }
};

int main(){
    while(1){
        BIT bit;
        int t=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        bit.init(n);
        FOR(i,1,n){
            int x;
            cin>>x;
            bit.add(i,x);
        }
        FOR(i,m,n){
            LL query=bit.getSum(i)-bit.getSum(t);
            ans=max(query,ans);
            t++;
        }
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	while (1) {
		int n, k, a[100005] = { 0 }, sum[100005] = { 0 };
		long long m = -9999999999;
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < k; i++) {
			sum[0] += a[i];
		}
		for (int i = 1; i < n - 2; i++) {
			sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
		}
		for (int i = 0; i < n - 2; i++) {
			if (m < sum[i]) {
				m = sum[i];
			}
		}
		cout << m << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
    int a[100010],n,k;
    while(cin>>n>>k,n||k){
        for(int i=0;i<n;i++)cin>>a[i];
        int mx=-1;
        int sum=0;
        for(int i=0;i<k;i++)sum+=a[i];
        mx=sum;
        for(int i=k;i<n;i++){
            sum-=a[i-k];
            sum+=a[i];
            mx=max(mx,sum);
        }
        cout<<mx<<endl;
    }
}

C++: #include<stdio.h>

//更新書き換え型
int MAX(int *num,int n,int k){
	int i,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	now = max;
	for(i = 0;i < n-k;i++){
		now += num[i+k]-num[i];
		if(max < now)
			max = now;
	}
	return max;
}
int main(){
	int n,k,max;
	int *num;
	int i;
	while(1){
		scanf("%d%d",&n,&k);
		if(n == 0 && k == 0)
			break;
		num = new int[n];
		for(i = 0;i < n;i++){
			scanf("%d",num+i);
		}
		max = MAX(num,n,k);
		printf("%d\n",max);
		delete[] num;
	}
	return 0;
}

C++: #include<iostream>

const int MAX_N = 1 << 17, INF = 1 << 24;
class BIT{
public:
	BIT(int _n)
		:n(_n){
		std::fill(bit, bit+n, 0);
	}
	int sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	int add(int i, int x){
		while(i <= n){
			bit[i] += x;
			i += i & -i;
		}
	}
private:
	int bit[MAX_N], n;
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		BIT b(n+1);
		for(int i=1;i<=n;i++){
			int a_i;
			std::cin >> a_i;
			b.add(i, a_i);
		}

		int res = -INF;
		for(int i=1;i+k-1<=n;i++){
			res = std::max(res, b.sum(i+k-1) - b.sum(i-1));
		}

		std::cout << res << std::endl;
	}
}

C++: # include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int n, k;
	while (cin >> n >> k) {
		vector<int> num;
		if (n == 0 && k == 0) {
			break;
		}
		int o;
		for (int i = 0; i < n; i++) {
			cin >> o;
			num.emplace_back(o);
		}
		int m = 0;
		for (int i = 0; i < n - k + 1; i++) {
			int h = 0;
			for (int j = 0; j < k; j++) {
				h += num[i + j];
			}
			m = max(m, h);
		}
		cout << m << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int n, k, a[200000], s, ret;
int main() {
	while (true) {
		cin >> n >> k; if (n == 0)break; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (i <= k)s += a[i]; }
		ret = s; for (int i = k + 1; i <= n; i++) { s -= a[i - k]; s += a[i]; ret = max(ret, s); }
		cout << ret << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	long long int ans;
	long long int kans;
	int num[100001];
	int n,k;
	int a,b;
	ans=0;
	scanf("%d%d",&n,&k);
	for(a=0;a<n;a++)scanf("%d",&num[a]);
	for(a=0;a<n-k;a++){
		kans=0;
		for(b=0;b<k;b++){
			kans+=num[a+b];
		}
		ans=max(ans,kans);
	}
	printf("%d\n",ans);
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <climits>
int main()
{
	int n,k;
	while(std::cin>>n>>k,n|k){
		int memo[100000];
		int ans = INT_MIN;
		int cnt = 0;
		int sum = 0;
		memset(memo,0,sizeof(memo));
		
		for(int i=0; i<n; i++){
			int a; std::cin>>memo[i];
			if(cnt<k){
				sum+=memo[i]; cnt++;
			}
			else{
				sum = sum-memo[i-k]+memo[i];
				//printf("sum:%d\n",sum);
			}
			if( k==cnt && sum>ans ) ans = sum;
			//printf("sum:%d\n",sum);
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    while(1){
    int n,k;
    cin >> n >> k;
    if(n==0 && k==0){
        break;
    }
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int s=0;
    int m=0;

    while(s+k-1<n){
        int cm=0;
        for(int j=0; j<k; j++){
            cm+=a[s+j];
        }
    if(cm>m){
        m=cm;
    }
    s++;
    }
    cout << m << endl;
    }
}