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;
  int a[100100];
  int b[100100];
  for(;;){
    cin >> n >> k;
    if(n==0 && k==0) break;
    
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    b[0] = 0;
    for(int i=0; i<n; i++){
      b[i+1] = b[i] + a[i];
    }
    int mx = -100000;
    for(int i=0; i<n-k; i++){
      int s = b[i+k+1] - b[i];
      if(mx < s) mx = s;
    }
    cout << mx << endl;
  }
  return 0;
}

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

int main(){
    int n, k;
    while(cin >>n >>k){
        if(n == 0 && k == 0) break;
        vector<int> vec;
        int max = 0, now = 0;
        for(int i = 0; i < k; i++){
            int tmp;
            cin >>tmp;
            max += tmp;
            now += tmp;
            vec.push_back(tmp);
        }
        for(int i = k; i < n; i++){
            int tmp;
            cin >>tmp;
            vec.push_back(tmp);
            now += tmp;
            now -= vec[i - k];
            if(max < now) max = now;
        }
        cout <<max <<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N, K;
    while(cin >> N >> K) {
        if(N == 0) break;
        vector<ll> a(N);
        for(int i = 0; i < N; ++i) cin >> a[i];

        vector<int> s(N+1, 0);
        for(int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        ll res = -INF;
        for(int i = 0; i <= N-K; ++i) {
            ll val = s[K+i] - s[i];
            if(res < val) res = val;
        }
        cout << res << endl;
    }

}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    vector<int> rsw(n+1);
    rsw.at(0)=0;
    for(int i=1;i<n+1;i++){
        rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
    }
    int ans =0;
    for(int i=k;i<n+1;i++){
        if(ans < rsw.at(i) - rsw.at(i-k)){
            ans = rsw.at(i) - rsw.at(i-k);
        }
    }
    cout << ans << endl;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,k;
    for(;;){
        scanf("%d%d",&n,&k);
        if(n==0&&k==0)break;
        int ma=0,now=0;
        vector<int> ins(n);
        for(int i=0;i<n;i++)scanf("%d",&ins[i]);
        for(int i=0;i<k;i++)now+=ins[i];
        for(int i=k;i<n;i++){
            now+=ins[i]-ins[i-k];
            ma=max(ma,now);
        }
        printf("%d\n",ma);
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int n, k;
  while(cin >> n >> k, n || k){
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i++) cin >> arr[i];
    int sum = 0, ans = 0;
    for(int i = 0; i < k; i++) sum += arr[i];
    ans = sum;
    for(int i = 1; i + k - 1 < n; i++){
      sum -= arr[i-1];
      sum += arr[i+k-1];
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main(){

	int n,k,a[100000],sum,ans;

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

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

	sum=0;

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

    ans=sum;

    for(int i=0;i<k;i++){
    	if(n==(k+i)){
    		break;
    	}
    	sum=sum-a[i]+a[k+i];
    	ans=max(ans,sum);
    }

    cout<<ans<<endl;


	}
}

C++: // Cumulative sum
#include <algorithm>
#include <cstdio>
using namespace std;

int sum[100010];
int main(void)
{
    int n, k;
    while(1) {
        scanf("%d %d", &n, &k);
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        for(int i=0; i<n; i++) sum[i+1] = sum[i] + a[i]; // sum[i] := a[0]??????a[i-1]?????§??????(sum[0]=0)

        int ans = -114514810;
        for(int i=0; i<n-k+1; i++)
            ans = max(ans, sum[i+1+k] - sum[i+1]);
        printf("%d\n", ans);
    }

    return 0;
}

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

using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main()
{
    long long n,k;
    long long temp;
    long long ans;
    vector<long long> num;

    cin >> n >> k;
    while(n!=0 && k!=0) {
        for(long long i=0; i<n; ++i) {
            cin >> temp;
            num.push_back(temp);
        }


        ans=0;

        for(long long i=0; i<k; ++i) {
            ans+=num[i];
        }

        if(k!=n) {
            for(long long i=k; i<n; ++i) {
                ans=MAX(ans,ans+num[i]-num[i-k]);
            }
        }

        cout << ans << endl;
        num.clear();
        cin >> n >> k;
    }
    return 0;
}

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

C++: // 2011/09/27 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, k;
		cin >> n >> k;
		if(n==0&&k==0)
			break;

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

		int sum = 0;
		for(int i=0; i<k; i++)
			sum += a[i];

		int max = sum;
		for(int i=k; i<n; i++){
			sum += a[i];
			sum -= a[i-k];
			if(max<sum)
				max = sum;
		}

		cout << max << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int a[100001];
int main(void)
{
	int n,k,sum,max=0,i,j;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0) break;
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		for(i=1;i<=n;i++){
			sum=0;
			if(i+k<=n){
				for(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>
#define INF 1000000
using namespace std;


main() {
  while(1) {
    int n, k;
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    int buf[k];
    fill_n(buf, k, 0);
    int maxS = -INF;
    int sum = 0;
    for(int i = 0; i < n; i++) {
      sum -= buf[0];
      for(int j = 0; j+1 < k; j++) buf[j] = buf[j+1];
      cin >> buf[k-1];
      sum += buf[k-1];
      if(i+1 < k) continue;
      if(maxS == -INF || sum > maxS) maxS = sum;
    }
    cout << maxS << endl;
  }
}

C++: #include <cstdio>

using namespace std;

int n=1,k=1,s,smax;
int a[100000];
int s1,s2;

int main(){
	while(1){
	scanf("%d %d\n",&n,&k);
	if(n==0&&k==0) break;
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
	printf("%d\n",smax);
	}
	return 0;
}