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<cstdio>
#include<cstring>
#include<algorithm>

#define MAX_N 100000

using namespace std;

int n, k;
int a[MAX_N];

int main()
{
	int max_v = 0;
	cin >> n >> k;

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

	for(int i = 0; i + k <= n ; i++)
	{
		int value = 0;

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

		max_v = max(max_v, value);
	}	

	cout << max_v << 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 sum[100003]={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<k;i++){
      if(i+k<=n){
      for(j=i;j<i+k;j++){
	sum[i]+=a[j];
      }
      }
      }

    sort(sum,sum+k,greater<int>());
  
    printf("%d\n",sum[0]);

  }

  return 0;

}

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

int main () {
    int n, k, a[100000], i, S[100000],m;
    cin >> n >> k;
    for(i=0;i<n;i++) {
        cin >> a[i];
    }
    for(i=0;i<n-k+1) {
        S[i]=S[i-1] - a[i-1] + a[i+k];
        m = max(m,S[i]);
    }
    cout << m << endl;
}

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

int solve(const vector<int>& v,int k) {
  int mx = MIN;
  int i = 0;
  auto begin = v.begin();
  while(i++ < v.size() - k) {
    mx = max(mx, accumulate(begin, begin + k, 0));
    begin++;
  }

  return mx;
}

int main() {
  int n, k;
  while (cin >> n >> k, n | k) {
    vector<int> v(n);
    for(auto i = 0; i < n; i++) cin >> v[i];

    cout << solve(v, k) << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	while(1){
        int n,k;
        int ans[10010] = {0};
        cin >> n >> k;
        if(n + k == 0) break;
        for(int i = 0; i < n; i++){
            cin >> ans[i];
        }
        int mx = 0,sum = 0;
        for(int i = 0; i < k; i++){
            sum += ans[i];
        }
        mx = sum;
        for(int i = k; i < n; i++){
            sum += ans[i];
            sum -= ans[i-k];
            mx = max(mx,sum);
        }
        cout << mx << endl;
	}
	return 0;
}

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

int main() {
	
	while(true){
	int n,k;
	cin >> n >> k;
	if(n==0&&k==0)break;
	
	vector<int> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	int sum=0;
	for(int i=0;i<k;i++){
		sum+=s[i];
	}
	int ans = sum;
	for(int i=0;i+k<n;i++){
		sum+=s[i+k]-s[i];
		if(sum>ans)ans=sum;
	}
	cout << ans << endl;
	}
	
	return 0;
}

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

using namespace std;


int main(){

while(1){
    int n, k;
    cin>> n>> k;
    if(n==0&&k==0) break;
    int a[n];
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
    }

    long long sum=0, ans=0;
    for(int i=0; i<k; i++){
        sum+=a[i];
        ans=max(ans, sum);
    }
    for(int i=0; k<n; i++, k++){
        ans=max(ans, sum);
        sum-=a[i];
        sum+=a[k];
    }
    
    ans=max(ans, sum);
    cout<< ans<< endl;
}
    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 <iostream>
#include <algorithm>
using namespace std;

int main() {
	while(true){
		int n,k;
		cin>>n>>k;
		if(n==0 && k==0){
			break;
		}
		
		int number[n],sum[n-k+1]={};
		for(int i=0;i<n;i++){
			cin>>number[i];
		}
		for(int i=0;i<n-k;i++){
			for(int j=0;j<k;j++){
				sum[i]+=number[i+j];
			}
		}
		
		int ans;
		for(int i=0;i<n-k-1;i++){
			ans=max(sum[i],sum[i+1]);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
main(){
  int n,k,a;
  int node1=0,node2,max;
  int ruiseki[100001]={0};
  while(1){
    cin>>n>>k;
    if(n==0&&k==0)break;
    node2=k;
    for(int i=1;i<=n;i++){
      cin>>a;
      ruiseki[i]=ruiseki[i-1]+a;
      if(i>=k){
	if(i==k){
	  max=ruiseki[node2]-ruiseki[node1];
	}
	else if(max<ruiseki[node2]-ruiseki[node1]){
	  max=ruiseki[node2]-ruiseki[node1];
	}
	node1++;
	node2++;
      }
    }
    cout<<max<<endl;
    node1=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=-1e9;
  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;
  }
}

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			max = MAX(max, data[i + k] - data[i]);
		}
		/*
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}*/
		
		printf("%d\n", max);
	}
	
	return (0);
}

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

using namespace std;

int main()
{
	int n, k, s, b;
	int a[100001];
	while (1)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		int m[100001] = { 0 };
		for (int i = 0;i < n;i++)
			cin >> a[i];

		m[0] = a[0];
		for (int i = 0;i < n;i++)
			m[i + 1] = m[i] + a[i];

		s = m[k] - m[0];
		for (int i = 0;i < n - k + 1;i++)
		{
			b = m[i + k + 1] - m[i + 1];
			if (s < b) 
				s = b;
		}

	}
	cout << s << endl;
	return 0;
}