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 <cstdio>
#include <algorithm>
#define ini 0
using namespace std;


int rlay[100001];

int main (){

while (1){
memset(rlay, 0,sizeof(rlay));

int n,k,input,ansmax=0;
cin>>n>>k;
if (n==0&&k==0)break;

rlay[0]=ini;
for (int i=1;i<=n;i++){
        cin>>input;
        rlay[i]=input+rlay[i-1];
}

for (int i=n;i-k>0;i--){
        ansmax = max ( rlay[i]-rlay[i-k] ,ansmax );
}

cout<<ansmax<<endl;

}
return 0;
}

C++: #include <iostream>
#include <algorithm>
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>>e[c];
		}
		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 <cstdlib>
using namespace std;

int main()
{
    int i, n, k, temp;
    cin >> n >> k;
    int a[n];
    for(i=0; i<n ;i++){
        cin >> a[i];
    }
    for(i=0; i<2; i++){cin >> temp;}
    int max_val;
    int S;
    //--init--
    S = 0;
    for(i=0; i<k; i++){
        S += a[i];
    }
    max_val = S;
    for(i=0; i<n-k; i++){
        S += a[i+k];
        S -= a[i];
        if(max_val < S){
            max_val = S;
        }
    }
    std::cout << max_val << std::endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, k;
ll bit[111111];
ll a;

ll sum(int i)
{
  ll s = 0LL;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, ll d)
{
  while(i <= n){
    bit[i] += d;
    i += i & -i;
  }
}

int main()
{
  while(cin >> n >> k, n){
    rep(i, 111111) bit[i] = 0LL;

    rep(i, n){
      cin >> a;
      add(i + 1, a);
    }

    ll res = sum(k);
    erep(i, k + 1, n) maxup(res, sum(i) - sum(i - k));
    cout << res << endl;
  }

  return 0;
}

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

using namespace std;

int n,m,cnt;
int ans,an;
int a[100000];

int main(void){

  while( cin >> n >> m , n || m ){

    ans = 0;

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

    for( int i = 0 ; i <= n - m ; i++ ){
      an = 0;
      cnt = 3;
      for( int j = i ; j < i + 3 ; j++ ){
	an += a[j];
      }
      ans = max( ans , an );
    }

    cout << ans << endl;

  }
  return 0;
}

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

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

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

		std::vector<int> vec(n);
		for (int i = 0; i != n; ++i)
			std::cin >> vec[i];

		int s = 0;
		for (int i = 0; i != k; ++i)
			s += vec[i];

		int m = std::numeric_limits<int>::min();
		m = std::max(s, m);
		for (int i = 0; i != n - k; ++i)
		{
			s -= vec[i];
			s += vec[i + k];
			m = std::max(s, m);
		}

		std::cout << m << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long 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 <iostream>
#include <queue>
using namespace std;
int main(){
	queue<int> a;
	while(1){
		int n,k,num,max,tmp;
		cin >> n >> k;
		if(!n&&!k) break;
		max=tmp=0;
		for(int i=0;i<k;i++){
			cin >> num;
			a.push(num);
			max+=num;
		}
		n-=k;
		tmp=max;
		while(n--){
			cin >> num;
			a.push(num);
			tmp+=a.back()-a.front();
			a.pop();
			if(max<tmp) max = tmp;
		}
		cout << max << endl;
		return 0;
	}
}

C++: #include <iostream>
#include <algorithm>
#define N 5000
using namespace std;
int main(){
  int n,k,data[N],maxv,sum,i,j;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    for(i=0;i<n;i++) cin >> data[i];
    maxv=-2000000000;
    for(i=0;i<n;i++){
      sum=0;
      if(i<=n-k){
	for(j=i;j<i+k;j++){
	  sum+=data[j];
	}
	maxv=max(maxv,sum);
      }
    }
    cout << maxv << endl;
  }
}

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

using namespace std;

void solve()
{
	int m, n;
	while(cin >> m >> n)
	{
		if(!m && !n)
		{
			break;
		}
		vector<int> Vec(m);
		for(int i = 0; i < m; ++i)
		{
			cin >> Vec[i];
		}
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			sum += Vec[i];
		}
		int max = sum;
		for(int i = 1; i < m - n + 1; ++i)
		{
			sum += Vec[i + n - 1] - Vec[i - 1];
			if(sum > max)
			{
				max = sum;
			}
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

constexpr int MAX_N = 1e5;
int a[MAX_N];

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

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

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

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

    cout << ans << endl;
  }

  return 0;
}

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

int main(){
  int n,k;
  long long int ans=-1000000000;
while(true){
  std::cin>>n>>k;
if(n==0&&k==0)break;
  std::vector<long long int>vec(n+1,0);
  long long int sub;
  for(int i=1;i<=n;i++){
    std::cin>>sub;
    vec.at(i)=vec.at(i-1)+sub;
  }
  for(int i=n;i>=k;i--){
    ans=std::max(vec.at(i)-vec.at(i-k),ans);
  }
  std::cout<<ans<<std::endl;
}
  return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=-1000000000,sum;
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
}

C++: #include<iostream>
main(){
  for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))
    for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<i)*a[i++-k],k<i&&M<s&&(M=s))std::cin>>a[i];
}