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 <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int a[100100];
int main()
{
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++)cin >> a[i];
	int ans=-INF;
	int base=0;
	for(int i=0;i<k;i++)base+=a[i];
	ans=base;
	for(int i=k;i<n;i++)
	{
		base-=a[i-k];
		base+=a[i];
		ans=max(ans,base);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    while(1){
        int N,K;
        cin>>N>>K;
        if(N ==  0 && K == 0) break;
        vector<long long> A(N);
        for(int i=0; i<N; i++) cin>>A[i];

        vector<long long> sum(N+1,0);
        for(int i=1; i<=N; i++){
            sum[i] = sum[i-1]+A[i-1];
        }

        long long ans=0;

        for(int i=0; i<=N-K; i++){
            ans = max(ans,sum[i+K]-sum[i]);
        }

        cout<<ans<<endl;
    }

    return 0;
}

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

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

C++: #include<iostream>
using namespace std;
int main(){
	int cnt,n,m,dat[110000];
	while(1){
	cin>>n>>m;
	if(n==0 && m==0){
		break;
	}
	for(int i=0;i<n;i++){
		cin>>dat[i];
	}
	int ans=0;
	for(int i=0;i<m;i++){
		ans+=dat[i];
	}
	cnt=ans;
	for(int i=m;i<n;i++){
		cnt+=dat[i]-dat[m-i];
		if(cnt>ans){
			ans=cnt;
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
long long int n,a[100000001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
return 0;
}

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

using namespace std;

int main()
{
	int n,m,i,j,ss,ans;
	vector<int> num;
	
	for(;;)
	{
		cin >> n >> m ;
		
		if(n==0 && m==0)
			break;
		
		num.clear();
		ss=0;
		
		for(i=0;i<n;i++)
		{
			int a;
			cin >> a ;
			num.push_back(a);
		}
		
		for(i=0;i<m;i++)
		{
			ss+=num[i];
		}
		
		ans=ss;
		m--;
		
		for(i=1;i<n-m;i++)
		{
			ss-=num[i-1];
			ss+=num[i+m];
			if(ans<ss)
			{
				ans=ss;
			}
		}
		
		cout << ans << endl;
	}
}

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

int main(){

  int n,k,i,j;

  while(1){

  int a[1000003]={0};
  int max=0,sum[1000003]={0};

    scanf("%d %d",&n,&k);

    if(n==0 && k==0){
      break;
    }

    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    for(i=0;i<n;i++){
      if(i+k<=n){
      for(j=i;j<i+k;j++){
	sum[i]+=a[j];
      }
      }
      if(max<sum[i]){
	max=sum[i];
      }
      }
  
    printf("%d\n",max);

  }

  return 0;

}

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

int main(){
	int n, k;
	while( scanf("%d %d", &n, &k), 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 = 0;
			for( int j=0; j<k; j++ ) sum += data[i+j];
			ans = max(ans, sum);
		}
		printf("%d\n", ans);
	}
}

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

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

last updated: 2013-07-10@17:04

 **********************************************/
#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 total=0, answer=0;
               

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

                for(int j=0; j<n-k+1; j++){
                        
                        if( j == 0){
                                for(int i=0; i<k; i++){
                                        total = total + data[j+i];
                                }
                                //cout << "subtotal1="<<total<<endl;
                        }else{
                                
                                total = total - data[j-1] + data[j+k-1];
                                //cout << "subtotal2="<<total<<endl;
                        }
                        //cout << "answer="<<answer<<"subtotal="<<total<<endl;
                        if( total > answer ){
                                answer = total;
                        }
                        //cout << "answer="<<answer<<endl;
                }
                
                cout << answer << endl;
                
        }

        return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
  int n,k,sn;
  int s,h,ans;
  while(cin>>n>>k){
    if(n==0&&k==0) break;
    int a[k];
    ans = -1000000;
    for(int i=0;i<k;i++) a[i] = -10000000;
    for(int i=0;i<n;i++){
      cin >> sn;
      h = 0;
      s = 0;
      while(h!=k){
	if(h==k-1){
	  a[h] = sn;
	}
	else  a[h] = a[h+1];
	s += a[h];
	h++;
      }
	if(ans<s) ans = s;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define MAX 100000
using namespace std;

int main(){
	int n, m;
	while(scanf("%d %d", &n, &m)){
		if(n == 0 and m == 0) break;
		int array[MAX];
		fill(array, array + MAX, 0);
		for(int i = 0; i < n; i++) scanf("%d", &array[i]);
		
		int sum = 0, max = 0;
		for(int i = 0; i < n - m; i++){
			sum = 0;
			for(int j = i; j < i + m; j++){
				sum += array[j];
			}
			max = sum > max ? sum : max;
		}
		printf("%d\n", max);
	}
	return 0;
}

C++: #include <iostream>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(void){
	int n,k;
	while (cin>>n>>k,n||k) {
		int a[100000];
		int sum=0;
		int m=0;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<k;i++)sum+=a[i];
		m=sum;
		for(int i=0;i<=n-k;i++){
			sum-=a[i+k-1];
			sum+=a[i];
			m=MAX(sum,m);
		}
		cout<<m<<endl;
	}
	return 0;
}