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>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値

int main() {
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        // 累積和を前計算
        vector<int> s(N+1, 0);
        for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        // 答えを求める
        long long res = -INF; // 最初は無限小の値に初期化しておく
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
const int INF = 1 << 30;
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int &x : a)cin >> x;
	int pos = 0;
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	int max = sum;
	for (int i = 0; i < n - k; i++) {
		sum += a[i + k] - a[i];
		max = std::max(max, sum);
	}
	cout<<max<<endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int n=0, k=0;
double a[100001] = {}, b[100001] = {}, ans=0;
int main(){
while (true){
n=0; k=0;
a[100001] = {}; b[100001] = {}; ans=0;
cin >> n >> k;
if (n == 0 || k == 0)	break;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
for (int x = 0; x<k; x++){
b[1] += a[1 + x];
}
ans=b[1];
for (int i = 2; i <= n; i++){
if (a[i + k - 1] == 0)	break;
b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
if (b[i]>b[i - 1]){
ans = b[i];
}
}
cout << ans << endl;
}
return 0;
}

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

typedef long long ll;

int n = 0;
int k = 0;
ll sum[100020] = {0};

ll solve()
{
  ll ans = -1001001001001;
  for (int i = 0; i < n; i++)
  {
    if (!i) ans = max(ans, sum[k-1]);
    else ans = max(ans, sum[i+k-1]-sum[i-1]);
  }
  return ans;
}

int main()
{
  while(1)
  {
    cin >> n >> k;
    if (!n && !k) break;
    for (int i = 0; i < n; i++)
    {
      int cmp = 0;
      cin >> cmp;
      if (i == 0) sum[0] = cmp;
      else sum[i] = sum[i-1] + cmp;
    }
    printf("%lld\n", solve());
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        int S[100010];
        for(int j=0;j<n;j++){
            cin >> a.at(j);
        }
        S[0]=0;
        for(int i=1;i<n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        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<iostream>
#include<algorithm>
using namespace std;

int main() {
	int n, k;
	while (cin >> n >> k, n, k) {

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

		int ans = 0;
		for (int i = 0;i <= n - k;i++) {
			int s = 0;
			for (int j = 0;j < k;j++) {
				s += a[i + j];
			}
			if (s > ans)ans = s;
		}
		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 = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			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<bits/stdc++.h>
using namespace std;
int N,K;
int a[100000];


int main()
{
    scanf("%d%d",&N,&K);
    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 ma=sum;
    for(int i=K;i<N;i++){
        sum-=a[i-K];
        sum+=a[i];
        ma=max(ma,sum);
    }
    printf("%d\n",ma);
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int s[100000];
	int n;
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int q=0;
	for(int i=0;i+k-1<=n;i++){
		int t=0;
		for(int ii=0;ii<k;ii++){
			t+=s[i+ii];
		}
		if(q<t)
			q=t;
	}
	cout<<q<<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 = -_UI64_MAX;

	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<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){

  int n,k,i,j;

  while(1){

  int a[100003]={0};
  int sum[100003]={0};
  int max=0;

    scanf("%d %d",&n,&k);

    if(n==0 && k==0){
      break;
    }

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

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

    sort(sum,sum+k,greater<int>());
  
    printf("%d\n",sum[0]);

  }

  return 0;

}