Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

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

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N,M;
        int lis[20000];
        cin>>N>>M;
        if(N==0&&M==0)break;
        for(int i=0;i<N;i++)cin>>lis[i];
        int now=0,ans=0;
        for(int i=0;i<M;i++)now+=lis[i],ans+=lis[i];
        for(int i=1;i+M<=N;i++)now=now-lis[i-1]+lis[i+M-1],ans=max(now,ans);
        cout<<ans<<endl;
    }
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int S[101010];
signed main(){
    while(cin>>N>>K,N||K){
    rep(i,N){
        cin>>S[i+1];
        S[i+1]+=S[i];
    }

    int ma=-1001001001001001001ll;
    for(int i=0;i+K<=N;i++)chmax(ma,S[i+K]-S[i]);
    cout<<ma<<endl;
    }
    return 0;
}

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

int a[100001],b[100001];

int f(int i,int j){
	return b[i] - b[j+1];
}

int main(){
	int n,k;
	while( cin >> n >> k , n||k ){
		b[0] = 0;
		for(int i=0 ; i < n ; i++ ){
			cin >> a[i];
			b[0] += a[i];
		}
		for(int i=1 ; i <= n ; i++ ){
			b[i] = b[i-1] - a[i-1];
		}
		int s = f(0,k-1);
		for(int i=1 ; i+k < n ; i++ ){
			s = max( s , f(i,i+k-1) );
		}
		cout << s << endl;
	}
}

C++: #include <cstdio>
#include <vector>
using namespace std;
#define MAX_N 100000

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	vector<int> data(MAX_N);
	for( int i=0; i<n; i++ ){
		scanf("%d", &data[i]);
	}
	int ans = 0;
	for( int i=0; i<=n-k; i++ ){
		int sum = 0;
		for( int j=0; j<k; j++ ) sum += data[i+j];
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,sum=0,num,box[10000],ans=0;
    while(1){
    cin>>n>>k;
    if(n==0&&k==0)break;
    if(n==k){
        for(int i=0;i<n;i++){
            cin>>num;
            ans+=num;
        }
    }
    else{
    for(int i=0;i<n;i++){
        cin>>num;
            if(i<k){
            sum+=num;
            box[i]=num;
        }
        else if(i>=k){
            if(sum-box[0]+num>ans)ans=sum-box[0]+num;
            sum+=num-box[0];
            for(int j=0;j<k;j++){
                if(j==k-1){
                    box[j]=num;
                }
                else box[j]=box[j+1];
            }
        }
    }
    }
    cout<<ans<<endl;
    ans=0;
    }
}

C++: #include<cstdio>
using namespace std;
int main(){
    int n,k;
    int s = 0;
    int a[100000] = {0};
    for(;;){
        scanf("%d%d",&n,&k);
        if(n == 0&&k == 0)break;
        for(int i = 0;i < n; i++){
            scanf("%d",&a[i]);
        }
        int x = 0;
        for(int i = 0;i < k; i++){
            x += a[i];
        }
        s = x;
        for(int i = 0;i < (n-k); i++){
            x -= a[i];
            x += a[i+k];
            if(s < x)s = x;
        }
        printf("%d\n",s);
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n, k;
    
    scanf("%d", &n);
    scanf("%d", &k);
    
    vector<int> a(n);
    
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    
    int sum = 0;
    
    for(int i = 0; i < k; i++)
    {
        sum += a[i];
    }
    
    int ret = sum;
    
    for(int i = k; i < n; i++)
    {
        sum += (a[i] - a[i - k]);
        
        ret = max(ret, sum);
    }
    
    printf("%d\n", ret);
    
    return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int n, k;
	while (scanf("%d %d", &n, &k), n || k) {
		int N[100001];

		for (int i = 1; i <= n; ++i) scanf("%d", &N[i]);

		int sum = 0;

		for (int i = 1; i <= k; ++i) sum += N[i];

		int a = sum;

		for (int i = k; i < n; ++i) {
			a += N[i+1] - N[i-k+1];
			sum = sum > a ? sum : a;
		}

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

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

int main(){
  int n,k;
  while(cin>>n>>k){
    if(n==0 && k==0) break;
    int a[n+1];
    for(int i=0; i<n; i++) cin >> a[i];
    int Max = a[0];

    for(int i=0; i<n; i++){
      int sum=0;
      for(int j=i; j<i+k; j++){
	if(j == n-1) break;
        sum+=a[j];
	//	cout << "j:" << j << " a[j]:" << a[j] << endl;
        if(Max < sum) Max = sum;
      }
    }
    cout << Max << endl;
  }
  return 0;
}

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

using ll = long long;

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

    // 累積和
    vector<ll> s(n + 1, 0);
    for (int i{}; i < n; ++i) {
      s[i + 1] = s[i] + a[i];
    }

    ll ans{numeric_limits<ll>::min()};
    for (int i{}; i <= n - k; ++i) {
      ans = max(ans, s[i + k] - s[i]);
    }

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

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 30;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int B = 320, MAX_N = 100000;

int A[MAX_N], buckets[MAX_N/B];

int sum(int l, int r){
    int res = 0;
    while(l < r && l % B > 0){res += A[l++];}
    while(l < r && r % B > 0){res += A[--r];}
    while(l < r){
        res += buckets[l/B];
        l += B;
    }

    return res;
}

int main(){
    int N, K;
    std::cin >> N >> K;

    REP(i, N){
        std::cin >> A[i];
        buckets[i/B] += A[i];
    }

    int res = -INF;
    REP(i, N){
        if(i+K <= N){
            res = std::max(res, sum(i, i+K));
        }
    }

    std::cout << res << std::endl;
}