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>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i++],k<i&&(s-=a[i-k-1]),M<s&&(M=s))std::cin>>a[i];}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    while (cin >> n >> k, n) {
        int sum = 0, res = -INT_MAX;
        vector<int> v(n, 0);
        for (int i=0; i<n; ++i) {
            cin >> v[i];
            sum += v[i] - (k <= i ? v[i-k] : 0);
            res = max(res, (k-1 <= i ? sum : -INT_MAX));
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	long long n, k, a[100005] = { 0 }, sum[100005] = { 0 }, m = -299999;
	cin >> n >> k;
	if (n == 0 && k == 0) return 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	sum[0] = a[0] + a[1] + a[2];
	for (int i = 1; i < n-2; i++) {
		sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
	}
	for (int i = 0; i < n - 2; i++) {
		cout << sum[i] << endl;
		if (m < sum[i]) {
			m = sum[i];
		}
	}
	cout << m << endl;
}

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

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n)

using namespace std;


int main(){
	while(1){
		int n,k;
		sint(n);
		sint(k);
		
		if(n==0) break;
		
		int kazu[100000];
		rep(i,n) sint(kazu[i]);
		
		int syoki=0;
		
		rep(i,k) syoki+=kazu[i];
		
		int maxi=syoki;
		rep(i,n-k){
			syoki-=kazu[i];
			syoki+=kazu[i+k];
			maxi=max(syoki,maxi);
		}
		
		printf("%d\n",maxi);
	}
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=0,sum;
	cin>>n>>k;
	while(n!=0){
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
	cin>>n>>k;
	}
}

C++: #include <stdio.h>
int main(){
while(1){
int k,n,i,x[100000];
long long int max,sum=0;
scanf("%d%d",&n,&k);
if(n==0 && k==0) break;
for(i=0;<n;i++){
scanf("%d",&x[i]);
}
for(i=0;i<k;i++){
sum+=x[i];
}
max=sum;
for(i=1;i<=n-k;i++){
for(j=i;j<i+k;j++){
sum=0;
sum+=x[j];
}
if(max<sum) max=sum;
}
printf("%lld\n",max);
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < k) total += a[i];
	    else total = total + a[i] - a[i-k];
	    if(ans < total) ans = total;
    }
    cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < k) total += a[i];
	    else{
	        total = total + a[i] - a[i-k];
	        if(ans < total) ans = total;
	    }
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;

int main(){
    int n,k;
    while(cin>>n>>k&&n&&k){
        vector<int> v(n+1,0);
        rep(i,0,n){
            cin>>v[i+1];
            if(i)v[i+1]+=v[i];
        }

        int ans=0;
        rep(i,k+1,n+1){
            ans=max(ans,v[i]-v[i-k]);
        }
        cout<<ans<<endl;
    }

    
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int n,k;
	int num[100001] = {0};
	while(scanf("%d%d",&n,&k),(n|k)){
		memset(num,0,sizeof(num));
		for(int i = 0; i < n; i++){
			scanf("%d",&num[i]);
		}
		int sum = 0;
		for(int i = 0; i < k; i++){
			sum += num[i];
		}
		int tmp = sum;
		for(int i = k; i < n; i++){
			tmp += num[i];
			tmp -= num[i-k];
			sum = max(sum,tmp);
		}
		printf("%d\n",sum);
	}
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値

int main() {
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> 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];
        
        // 答えを求める
        long long res = -INF; // 最初は無限小の値に初期化しておく
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}

C++: 
#include<iostream>
main(){
  for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){
    for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<=i)*a[i-k],(k<++i)&&(M<s)&&(M=s)){
      std::cin>>a[i];
    }
  }
}

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

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

    int* num_sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
      cin >> num_sequence[i];
      //cout << i << ':' << num_sequence[i] << endl;
    }

    max = -999999;
    for (int j = 0; j < n-k+1; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    delete[] num_sequence;
  }
  return 0;
}

C++: #include<fstream>
using namespace std;
int main(){
ifstream fin("input.txt");
ofstream fout("output.txt");
long long n,k,i,a[100000],s[100000],x;
while(fin>>n>>k,n*n+k*k){
for(i=0;i<n;i++)fin>>a[i];
for(s[0]=i=0;i<k;i++)s[0]+=a[i];
for(i=1;i<n-k+1;i++)s[i]=s[i-1]-a[i-1]+a[i+k-1];
x=-1000000000;
for(i=0;i<n-k+1;i++)if(x<s[i])x=s[i];
fout<<x<<endl;
}
return 0;
}

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

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