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>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int gomi;
  cin >> gomi >> gomi;
  int ans = 0;
  for(int i = 0; i < k; i++) {
    ans += a[i];
  }
  int mx = ans;
  for(int i = 0; i < n - k; i++) {
    mx = mx + a[k + i] - a[i];
    ans = max(mx, ans);
  }

  cout << ans << endl;
  return 0;
}

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

int main(){
	int n,k,max,buf,*a;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = buf = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			for(int i = 0; i < k-1; i++){
				buf += a[i];
			}
			
			for(int i = k-1; i < n; i++){
				buf += a[i];
				if(max < buf) max = buf;
				buf -= a[i-k+1];
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

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

long long int sum,k,n,num[200000];

int main(){
    long long int ans=-1000000000000;
    cin >> n >> k;

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

    for(int i=0;i<n-k;i++){
        for(int j=i;j<i+k;j++){
            sum+=num[j];
        }
        if(ans<sum)ans=sum;
        sum=0;
    }

    cout << ans << endl;

return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		cin>>a>>b;
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>d;
			e[c]=d;
		}
		for (int f=0;f<=a-b;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
			if (e[f]>=max) max=e[f];
		}
		cout<<max<<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];
            }
            sum_max = max(sum ,sum_max);
        }
        cout << sum_max << endl;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
	int n, k;
	int a[123456];
	for (;;) {
		scanf("%d %d", &n, &k);
		if (!n && !k) break;
		rep(i, n) scanf("%d", &a[i]);

		long long int ps = 0;
		rep(i, k) ps += a[i];

		long long int big = ps;
		for (int i = 0; i < n - k; i++) {
			ps -= a[i];
			ps += a[i + k];
			big = max(ps, big);
		}

		printf("%lld\n", big);
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	int n, k, ans = -1000000, sum = 0;
	cin >> n >> k;
	int yj[200008] = {};
		for(int i = 0; i < n; i++){
			cin >> yj[i];
		}
	for(int i = 0; i < k; i++){
		sum += yj[i];
	}
	for(int i = 0; i < n - k; i++){
		sum += yj[i+k];
		sum -= yj[i];
		ans = max(sum, ans);
	}
	cout << ans << endl;
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

signed main()
{
    int n, k;
    
    static int a[100010], sum[100010];

    while (cin >> n >> k, n) {
        rep(i, n) cin >> a[i];

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

        int ma = -1e9;

        rep(i, n - k + 1) {
            ma = max(ma, sum[i + k] - sum[i]);
        }

        cout << ma << endl;
    }
}

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

using namespace std;

int main(){
	while (1){
		int n, k;
		int b[100000] = {};
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0)return 0;
		int base = 0;
		for (int i = 0; i < k; i++){
			int a;
			scanf("%d", &a);
			b[i] = a;
			base += a;
		}
		int sa = 0;
		for (int i = k; i < n; i++){
			int c;
			scanf("%d", &c);
			sa = max(sa, c - b[0]);
			for (int j = k-1; j > 0; j--){
				b[j-1] = b[j];
			}
			b[k-1] = c;
		}
		printf("%d\n", sa + base);
	}
}

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

using namespace std;

int main(){
	while (1){
		int n, k;
		int b[100000] = {};
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0)return 0;
		int base = 0;
		for (int i = 0; i < k; i++){
			int a;
			scanf("%d", &a);
			b[i] = a;
			base += a;
		}
		int sa = 0;
		for (int i = k; i < n; i++){
			int c;
			scanf("%d", &c);
			sa = max(sa, c - b[0]);
			for (int j = 1; j < k; j++){
				b[j] = b[j - 1];
			}
			b[0] = c;
		}
		printf("%d\n", sa + base);
	}
}

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

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

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

long long int sum,k,n,num[200000],to;

int main(){

    while(1){

    long long int ans=-1000000000;
    cin >> n >> k;
    if(n==0&&k==0)break;

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

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

    for(int i=k;i<n;i++){
        if(ans<sum)ans=sum;
        sum-=num[to++];
        sum+=num[i];
    }

    cout << ans << endl;

    sum=0;
    ans=0;
    to=0;

    }


return 0;
}

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

int n, k;
int a[100000];
int ra[100001];	//ra[i] = a[0] + ??? + a[i-1]

int main() {
	while (cin >> n >> k) {
		if (!n) { break; }
		ra[0] = 0;
		for (int i = 0; i < n; i++) {
			ra[i+1] = ra[i] + a[i];
		}

		int ans = -1000000001;
		for (int i = k; i <= n; i++) {
			ans = max(ans, ra[i] - ra[i-k]);
		}

		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
int n,k;
cin >> n >> k;
while(n!=0||k!=0){
  int i=0, a[100000], S[100000];
  S[0] = 0;
  while(i < n){
    cin >> a[i];
    if (i>=1)
      S[i] = S[i-1]+a[i-1];
    i++;
  }
  int q = i;
  i = 0;
  int m = a[0];
  while(k+i<=q){
    if (m > S[i+k-1]-S[i])
      m = S[i+k-1]-S[i];
    i++;
  }
  cout << m << endl;
}
cin >> n >> k;
}