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>
using namespace std;

int main()
{
  int n,k;
  cin >> n >> k;
while(n!=0||k!=0){
  int l, i=0, a[100000], S[100000];
  S[0] = 0;
  while(cin >> l){
    a[i] = l;
    if (i>=1)S[i] = S[i-1]+a[i-1];
    i++;
  }
  int q = i; i = 0;int m = a[0];
  while(k+i<=q){
    if (m > S[i+k-1]-S[i])
    m = S[i+k-1]-S[i];
    i++;
  }
  cout << m << endl;
}
cin >> n >> k;
}

C++: #include <cstdio>
#include <vector>
using namespace std;
#define MAX_N 100000

int main(){
	int n, k;
	scanf("%d %d", &n,&k);
	vector<int> data(MAX_N);
	for( int i=0; i<n; i++ ){
		scanf("%d", &data[i]);
	}
	int ans = 0;
	for( int i=0; i<n-k; i++ ){
		int sum = data[i] + data[i+1] + data[i+2];
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
}

C++: #include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)

int n,k,a[100000];

int main(){
	while(cin>>n>>k&&n){
		rep(i,n)cin>>a[i];
		int s=0;
		rep(i,k)s+=a[i];
		int ans=s;
		rep(i,n-k){
			s+=a[k+i]-a[i];
			ans=max(ans,s);
		}
		cout<<ans<<endl;
	}
}

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

int N, K, a[1000000];
int main()
{
  while(true)
  {
    cin >> N >> K;
    if(!N)
      break;
    int v = 0;
    for(int i = 0; i < N; i++)
    {
      cin >> a[i];
      if(i < K)
        v += a[i];
    }
    int ans = v;
    for(int i = K; i < N; i++)
      ans = max(ans, v = v + a[i] - a[i - K]);
    cout << ans << endl;
  }
}

C++: #include <stdio.h>
#include <string.h>

#define MAX_BIT_SIZE 100001

int BIT[MAX_BIT_SIZE];
int n;

int sum(int index) {
    int ret = 0;

    while (index > 0) {
        ret += BIT[index];
        index -= index & -index;
    }

    return ret;
}

void add(int index, int value) {
    int i = 1;
    while (index <= n) {
        BIT[index] += value;
        printf("%d\n", index);
        index += i;
        i <<= 1;
    }
}

int main() {
    while (1) {
        int k;
        int i;
        int max_count = 0;


        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        memset(BIT, 0, MAX_BIT_SIZE);

        for (i=0;i<n;i++) {
            int d;
            scanf("%d", &d);
            add(i, d);
        }

        for (i=0;i<n-k;i++) {
            int now_count = sum(i+k) - sum(i);
            if (now_count > max_count)max_count = now_count;
        }

        printf("%d\n", max_count);
    }
}

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

int main(){
	int n,k,max,buf,*a;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = buf = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			for(int i = 0; i < k-1; i++){
				buf += a[i];
			}
			
			for(int i = k-1; i < n; i++){
				buf += a[i];
				max = (max < buf)?buf:max;
				buf -= a[i-k+1];
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

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

int main()
{
	int n, k, i, inp, sum, max=0;
	int *a;
	cin >> n >> k;
	a = new int[n];
	
	for (i = 0; i < n; i++){
		cin >> inp;
		a[i] = inp;
	}
	
	int o1, o2;
	cin >> o1 >> o2;

	for (i = 0; i < n - 2; i++){
		sum = a[i] + a[i + 1] + a[i + 2];
		if (sum > max){ max = sum; }
	}

	cout << max << endl;

	delete[] a; 
	return 0;
}

C++: /**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@16:16

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){
                
                int n=0;
                int k=0;
                int all=0;
                int total=0, answer=0;
                vector<int> data(5000);

                cin >> n >> k;
                //cout << "n=" << n << "k=" << k << endl;
                if(n==0 && k==0)break;
                
                for(int i=0; i<n; i++){
                        cin >> data[i];
                }
               

                for(int j=0; j<n-k; j++){
                        
                        for(int i=0; i<k; i++){
                                total = total + data[j+i];
                        }
                        if( answer < total){
                                answer = total;
                        }
                        total = 0;
                }

                cout << answer << endl;
                
        }

        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];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,k;
  while(cin>>n>>k,n+k){
    vector<ll>sum(n);
    ll ans=-llINF;
    for(int i=0;i<k-1;i++){
      cin>>sum[i];
    }
    for(int i=k-1;i<n;i++){
      cin>>sum[i];
      ll mi=0;
      for(int j=0;j<k;j++){
	mi+=sum[i-j];
      }
      //cout<<mi<<endl;
	ans=max(mi,ans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

ll N,K;
ll a[100005];

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,k,res=-1;
  while(cin>>n>>k,n+k){
    vector<int> ary(n);
    int sum = 0;
    rep(i,n){
      cin>>ary[i];
      sum += ary[i];
      if(i >= k){
	sum -= ary[i-k];
      }
      res = max(res,sum);
    }
    cout<<res<<endl;
  }
}