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<bits/stdc++.h>
using namespace std;

int main(){

  int n, k;
  
  while(cin >> n >> k, n|k){
    
    int ans = 0, data[111111] = {};
    for(int i=0;i<n;i++) cin >> data[i];
    for(int i=1;i<n;i++) data[i] += data[i-1];
    
    for(int i=0;i<n-k;i++) ans = max(ans, data[i+k] - data[i]);
    
    cout << ans << endl;
  }
  
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
  cin >> n >> k;
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    cin >> set[i];
  }

  for(int i=0,sum=0;i<n-k;i++,sum=0){
    for(int j=i;j<i+k;j++){
      sum += set[j];
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  cout << max << endl;
  }
}

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

int main() 
{
	int n = -100000;
	int a, b;
	while (cin >> a >> b, a || b) {
		vector<int>s(a);
		for (int c = 0; c < a; c++)cin >> s[c];
		int m = 0;
		for (int e = 0; e < b; e++) {
			m += s[e];
		}
		if (n < m)n = m;
		for (int d = 0; d < a - b; d++) {
			m -= s[d];
			m += s[d + b];
			if (n < m)n = m;
		}
		cout << n << endl;
	}
}

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

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

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

int main(){
  int n,k,sum,summ;
  scanf ("%d %d",&n,&k);
  while(n){
    sum=0;
    summ=0;
    vector<int> a(n);
    for(int t=0;t<n;t++){
      scanf ("%d",&a[t]);
    }
    for(int t=0;t<k;t++){
      sum+=a[t];
    }
    summ=sum;
    for(int t=k;t<n;t++){
      sum=sum+a[t]-a[t-k];
      if(sum>summ){
        summ=sum;
      }
    }
    printf("%d\n",summ);
    scanf ("%d %d",&n,&k);
  }
}

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

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

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

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


int main(){
  int n, k;
  int a[100100];
  for(;;){
    cin >> n >> k;
    if(n==0 && k==0) break;
    
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    int mx = -100000;
    for(int i=0; i<n-k; i++){
      int s = 0;
      for(int j=0; j<k; j++){
        s += a[i+j];
      }
      if(mx < s) mx = s;
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa )
{
	int temp = 0;
	int i;
	/*
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	*/
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa, 0);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0));
	}
}

C++: #include <iostream>
#include <algorithm>
#define INF (2 << 28)
using namespace std;

int main(){
    
    int n, k, a[111111];
    int sum[111111];
    
    while(cin >> n >> k, n||k){
        fill_n(sum, 111111, 0);
        for(int i = 0; i < n; i++) cin >> a[i];
        
        sum[0] = a[0];
        for(int i = 0; i < n; i++) sum[i] = sum[i - 1] + a[i];
    
        int maxi = -INF;
        for(int i = k; i < n; i++)
            maxi = max(maxi, sum[i] - sum[i - k]);
        
        cout << maxi << endl;
    }
}

C++: template<class T> void chmax(T & a, T b) { if (a < b) a = b; }
template<class T> void chmin(T & a, T b) { if (a > b) a = b; }

#define rep(i, n) for(int i=0; i<n; i++)
#include <bits/stdc++.h>
using namespace std;

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

		vector<int> a(n);
		rep(i, n) scanf("%d", &a[i]);
		vector<int> s(n + 1, 0);
		rep(i, n) s[i + 1] = s[i] + a[i];

		int res = -(1 << 30);
		rep(i, n - k) {
			chmax(res, s[i + k] - s[i]);
		}
		cout << res << endl;
	}
}

int main(void) {
	solve();

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void){
    for(int i = 0; i < 5; i++){
        long long n, k, a, sum = 0, ans = 0; 
        cin >> n >> k;
        if(n==0&&k==0){
            return 0;
        }
      int test[100001] = { 0 };
      for(int h = 0; h < n; h++){
          cin >> a;
          test[h] = a;
          if(h < k){
            sum += a;
            ans += a;
          }
      }
      for(int h = 0; h < n - k; h++){
        ans = max(ans, sum - test[h] + test[h + k]);
        sum = sum - test[h] + test[h + k];
      }
       cout << ans << endl;
   }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

int a[1000000];

int main()
{
    int n, k;
    while(cin >> n >> k && n && k) {
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        ll pre = 0;
        for(int i = 0; i < k; i++) {
            pre += a[i];
        }
        
        ll ret = pre;
        for(int i = 0; i < n - k; i++) {
            cout << pre << " " << a[i] << " " << a[k + i] << endl;
            pre = pre - a[i] + a[k + i];
            ret = max(ret, pre);
        }
        
        cout << ret << endl;
    }
}

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

int main() {
	while (1) {
		int i, j, n, k, sum = 0, maxsum;

		cin >> n >> k;
		if (n == 0)break;
		int *a = new int[n + 1];
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}

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

		maxsum = sum;

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

		cout << maxsum << endl;
	}
	

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    vector<int> ans(0);
    while(1){
        cin>>n>>k;
        if(n==0&&k==0){
            break;
        }
        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;
    }
    
}