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<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i < n - k + 1; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

C++: #include<stdio.h>

long long int re[100001];

int main(){
	int n,k,i;
	long long c;
	re[0]=0;
	while(0<=scanf("%d%d",&n,&k)){
		if(n==0 && k==0)break;
		
		for(i=1;i<=n;i++){
			scanf("%lld",&c);
			re[i]=re[i-1]+c;
		}
		c=re[k];
		for(i=1;i+k-1<=n;i++){
			if(c<re[i+k-1]-re[i-1])c=re[i+k-1]-re[i-1];
		}
		printf("%lld\n",c);
	}
	return 0;
}

C++: #include <cstdio>

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

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

using namespace std;

int n,m,cnt;
int ans_max,an_max,an;
int a[100000];

int main(void){

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

    ans_max = -99999999;

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

    for( int i = 0 ; i <= n - m ; i++ ){
      an = 0;
      cnt = 3;
      for( int j = i ; j < i + 3 ; j++ ){
	an += a[j];
      }
      
      ans_max = max( ans_max , an );
      
    }

    cout << ans_max << endl;

  }
  return 0;
}

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

int main(){
  int n,k,x;
  vector<int> s;
  int start,end,ans=0,sum;
  
  while(1){
  
    cin>>n>>k;
    if(n==0 && k==0) break;
  
    for(int i=0;i<n;i++){
      cin>>x;
      s.push_back(x);
    }
    
    start=0;end=k;sum=0;
    for(int i=start;i<end;i++){
        sum+=s[i];
    }
    ans=max(ans,sum);
    
    while(end<n){
      sum+=s[end];
      sum-=s[start];
      ans=max(ans,sum);
      
      start++;end++;
    }
  
    printf("%d\n",ans);
    ans=0;sum=0;
    s.clear();
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int n,k;
    while (cin >> n >> k) 
    {
        if (n == 0 && k==0) 
        {
            break;
        }
        vector<int> vec(n);
        //vector<int> sum(n -k +1);
        int sum=0;
        int sum_max=0;
        int input;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];
        }
        for (int i = 0; i < n - k + 1; i++) 
        {
            sum=0;
            for (int j = 0; j < k; j++) 
            {
                sum += vec[i + j];
            }
            if (sum_max < sum) 
            {
                sum_max = sum;
            }
        }
        cout << sum_max << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int a[MAX_N];

int main()
{
	int n,k;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0){
			break;
		}
		rep(i,n){
			scanf("%d",&a[i]);
		}
		ll ans=0;
		ll s=0;
		int id=0;
		while(id<n){
			s += a[id];
			if(id>=k){
				s-=a[id-k];
				ans = max(ans,s);
			}else if(id==k-1){
				ans = s;
			}
			id++;
		}
		cout << ans << "\n";
	}
	return 0;
}

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

/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */

int main()
{
	int n, l;

    while (cin >> n >> l, n || l){
        int a[100000];
        REP(i, n){
            cin >> a[i];
        }

        int sum = 0;
        REP(i, n - (n - l)){
            sum = max(sum, a[i] + a[i + 1] + a[i + 2]);
        }

        CL(sum);
    }

	return (0);
}

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

using ll = long long;

constexpr int MAX_N = 100000;

int N, K;
ll csum_A[MAX_N];

int main(){

	while(true){

		std::cin >> N >> K;

		if(N == 0 && K == 0) break;

		for(int i = 0; i < N; ++i){

			ll input;

			std::cin >> input;

			if(i == 0) csum_A[i] = input;
			else csum_A[i] = csum_A[i - 1] + input;
		}

		ll ans = csum_A[K - 1];

		for(int i = 0; i < N - K; ++i){

			ans = std::max(ans, csum_A[i + K] - csum_A[i]);

		}

		std::cout << ans << std::endl;
	}

	return 0;
}

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

int main(){

  int n,k,i,j;

  while(1){

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

    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+=a[j];
      }
      }
      if(max<sum){
	max=sum;
	sum=0;
      }
      }
  
    printf("%d\n",max);

  }

  return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n, k;
		double a[100001] = {}, b[100001] = {}, ans;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		else{
			cout << ans << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n = 0, k = 0;
int a[100001] = {}, b[100001] = {};
int ans;
int main(){
	while (true){
		n = 0; k = 0;
		ans = 0;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[x + 1];
		}
		ans=b[1];
		for (int i = 2; i <= n; i++){
			if (i+k==n+1)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			ans = max(b[i], ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <list>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;

int main(int, char**){
    int n,k;
    while(1){
	cin >> n >> k;
	if(n==0&&k==0) break;
	vector<int> as(n);
	for(int i(0);i<n;++i) cin >> as[i];
	int sum=0;
	for(int i(0);i<k;++i) sum += as[i];
	for(int i(k);i<n;++i){
	    int tmp = sum + as[i] - as[i-k];
	    if(tmp>sum) sum = tmp;
	}
	cout << sum << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long m[100000][2];
int main(){
while(1){
long long n,k,i,j,x=0;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=0;i<n;i++)cin>>m[i][0];
m[0][1]=m[0][0];
for(i=1;i<n;i++){
m[i][1]=m[i-1][1]+m[i][0];
}
x=m[k-1][1];
for(i=k;i<n;i++){
x=max(x,m[i][1]-m[i-k][1]);
}
cout<<x<<endl;
return 0;
}
}