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 <stdio.h>

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

C++: #include <iostream>
 
int kk[100000];
 
int main(){

while(1){

int s=0;
int n,k;
std::cin>>n>>k;
 
if(n==0&&k==0)
break;

for(int i=0;i<k;i++){
std::cin>>kk[i];
s+=kk[i];
}
 
int st=s;
 
for(int i=k;i<n;i++){
std::cin>>kk[i];
s+=kk[i]-kk[i-k];
if(s>st)
st=s;
}
 
std::cout<<st<<std::endl;

}

}

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

vector<ll> ret;

void solve(vector<ll>& a, ll k) {
    ll n = a.size();
    vector<ll> cs(n+1, 0);
    for(int i = 1; i < n+1; i++) {
        cs[i] = cs[i-1];
        cs[i] += a[i-1];
    }

    ll ans = (-1) * INF;
    for(int i = 0; i < n+1; i++) {
        ll now = cs[i+k] - cs[i];
        ans = max(ans, now);
    }
    ret.push_back(ans);
}

int main() {
    do {
        ll n, k;
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        vector<ll> a(n, 0);
        for(int i = 0; i < n; i++) cin >> a[i];
        solve(a, k);
    } while(true);

    for(auto &r : ret) {
        cout << r << endl;
    }
}

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

using namespace std;

int main(){


    int n,k,ans=0,ans2=0,ans3=0;
    while(1){
    scanf("%d%d",&n,&k);
    if(n==0&&k==0)break;
    int num[n];
    for(int y=0;y<n;y++){
        scanf("%d",&num[y]);
    }
        for(int a=0;a<k;a++){
        ans+=num[a];
        }
        ans3=ans;
    for(int j=0;j<n-k;j++){
        ans2=ans-num[j]+num[j+k];
        if(ans3<ans2){
            ans3=ans2;
        }
    ans=ans2;
    ans2=0;
    }
    printf("%d\n",ans3);
    }

return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	while (cin >> n >> k&&n != 0 && k != 0) {
		long long  a[100000], sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (i < k) sum += a[i];
		}
		long long s = 1, e = k, f;
		while (e < n) {
			f = sum;
			sum += a[e];
			sum -= a[s - 1];
			sum = max(sum, f);
			s++;
			e++;
		}
		cout << sum << endl;
	}
}

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

int main()
{
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    if ((n|k) == 0)
      break;

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

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

    int ans = a[k-1];
    for (int i = k; i < n; ++i)
      ans = max(ans, a[i]-a[i-k]);

    printf("%d\n", ans);
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i<n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        int x=S[k];
        for(int l=1;l<n-k;l++){
            if(x<S[k+l]-S[l]){
                x=S[k+l]-S[l];
            }
             cout << x << endl;
            cin >> n >> k;
        }

    }

}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;
    int ans = -50000;
    int sum = 0;
    int lastNum;
    vi series;
    while(cin >> n >> k, n+k){

        for(int i=0; i < n; i++){
            int m;
            cin >> m;
            series.push_back(m);

            if(i < k-1) sum += m;
            else {
                sum += m-series[i-k];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
}

C++: #include <stdio.h>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		scanf("%d %d",&a,&b);
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			scanf("%d",&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];
		}
		printf("%d\n",max);
	}
	return 0;
}

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

int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		int ans=0;
		queue<int> que;
		for(int i=0,num;i<m;i++){
			cin>>num;
			que.push(num);
			ans+=num;
		}
		for(int i=m,num,sum=ans-que.front();i<n;i++){
			que.pop();
			cin>>num;
			sum+=num;
			ans=max(ans,sum);
			sum-=que.front();
			que.push(num);
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

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

        int sum = 0;
        int ans = 0;
        queue<int> q;
        for(int i = 0; i < n; ++i) {
            int num;
            scanf("%d", &num);

            sum += num;
            if(i == k-1) ans = sum;
            if(i >= k) {
                sum -= q.front();
                q.pop();
                ans = max(ans, sum);
            }
            q.push(num);
        }

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

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i==n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        int x=S[k];
        for(int l=1;l==n-k;l++){
            if(x<S[k+l]-S[l]){
                x==S[k+l]-S[l];
            }
             cout << x << endl;
            cin >> n >> k;
        }

    }

}

C++: #include <algorithm>
#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> v(n);
    for (auto&& w : v) cin >> w;
    vector<int> s(n + 1, 0);
    for (int i = 0; i < n; i++) {
      s[i + 1] = s[i] + v[i];
    }
    int ret = 0;
    for (int i = 0; i + k < n + 1; i++) {
      int sm = s[i + k] - s[i];
      ret = max(ret, sm);
    }
    cout << ret << endl;
  }
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  
  long long n,k,max=0,ans,i;
  cin >> n >> k;
  long long a[n];
  
  for(i = 0;i < n;i++){
    scanf("%lld",&a[i]);
    
    if(i < k){
      max += a[i];
      ans = max;
    }
    else {
      max = max + (a[i] - a[i-k]);
      if(ans < max) ans = max;
    }
  }

  printf("%lld\n",ans);
  return (0);
}