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>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

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



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<long long int> num(n);
        rep(i, n) std::cin >> num.at(i);

        long long int sum = std::accumulate(num.begin(),num.begin()+k,0LL);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		int data[n];
		long long sum[n-k+1];
		sum[0]=0;
		rep(i,n){
			cin>>data[i];
			if(i<k)sum[0]+=data[i];
		}
		rep(i,n-k){
			sum[i+1]=sum[i]+data[i+k]-data[i];
		}
		sort(sum,sum+n-k+1);
		cout<<sum[n-k]<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<algorithm>
#include<queue>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int ini[10001];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,n){
		scanf("%d",&ini[i]);
	}
	
	int sum=0;
	rep(i,m){
		sum+=ini[i];
	}
	
	int maxi=sum;
	for(int i=m;i<n;i++){
		sum-=ini[i-m];
		sum+=ini[i];
		maxi=max(maxi,sum);
	}
	
	printf("%d\n",maxi);
}

C++: #include<stdio.h>
int ar[100000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,k;
	int i,j;
	while(1){
	int ans=0;
	scanf("%d %d",&n,&k);
	if(n==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&ar[i]);
	int res=0;
	for(i=0;i<k;i++)res+=ar[i];
	ans=max(ans,res);
	for(i=k;i<n;i++){
		res+=ar[i];
		res-=ar[i-k];
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	}
}

C++: #include <iostream>

using namespace std;
int main()
{
    while(true){
        int i, k;
        cin >> i;
        cin >> k;
        if( i == 0 && k == 0)
            break;
        int a[i], b[i];
        
        for(int j = 0 ; j < i ; j++)
            cin >> a[j];
        
        b[0] = a[0];
        for(int j = 0 ; j < i-1 ; j++)
            b[j+1] = b[j] + a[j+1];
        
        int N = b[k-1];
        for(int j = 0 ; j < i-k ; j++){
            if( b[j+k] - b[j] > N ){
                N = b[j+k] - b[j];
            }
        }
        
        cout << N <<endl;
    }
}

C++: #include<stdio.h>

#include<algorithm>


using namespace std ;



int main()
{
	int n ,k ;

	while( 1 )
	{
		scanf( "%d %d" ,&n ,&k ) ;


		if( !( n | k ) )
		{
			return 0 ;
		}


		int if_k = k - 1 ;

		int ans = -10001 ,other[ 100000 ] ;
		
		int sum = 0 ;

		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&other[ i ] ) ;

			sum += other[ i ] ;


			if( i >= if_k )
			{
				ans = max( ans ,sum ) ;
			}

			if( i > if_k )
			{
				sum -= other[ i - k ] ;
			}
		}


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

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

int n,k,b[100100]={},sum=0,sum1=0,ans=0,j=0;

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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int n, k;
	ll result, tmp;

	cin >> n >> k;

	vi nums(n);
	result = -10000000000000;

	REP(i, n) {
		cin >> nums[i];
	}

	REP(i, n-k+1) {
		tmp = 0;

		REP(j, k) {
			tmp += nums[i+j];
		}

		if(result < tmp) {
			result = tmp;
		}
	}

	cout << result << endl;

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,e[100000]={0};
		cin>>a>>b;
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>d;
			e[c]=d;
		}
		for (int f=0;f<a-b+1;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
		}
		sort(e,e+100000);
		cout<<e[99999]<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,k;
  while(cin>>n>>k,n){
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int s[n+1];
    s[0]=0;
    for(int i=0;i<n;i++) s[i+1]=s[i]+a[i];
    int ans=s[k];
    for(int i=0;i<n-k;i++) ans=max(ans,s[i+k]-s[i]);
    cout<<ans<<endl;
  }
  return 0;
}