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 n2[100001];
int main() {
	int n, k;
	int cnt = 0, cnt_max = -10001;
	while (1) {
		cin >> n >> k;
		if (n == 0 && k == 0)return 0;
		for (int i = 1; i <= n; i++) {
			cin >> n2[i];
		}
		for (int i = 1; i <= n - k + 1; i++) {
			cnt = n2[i];
			for (int j = 1; j < k; j++) {
				cnt += n2[i + j];
			}
			if (cnt_max < cnt) {
				cnt_max = cnt;
			}
		}
		cout << cnt_max << endl;
		cnt_max = 0;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <climits>

#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

static const int DAT_SIZE = 1<<18;
typedef long long ll;

ll data[DAT_SIZE], datb[DAT_SIZE];

void add(ll a, ll  b, ll x, ll  k, ll  l, ll  r){
    
    if(a <= l && r <= b){
        data[k] += x;
    }
    else if(l < b && a < r){
        datb[k] += (min(b, r) - max(a, l)) * x;
        add(a, b, x, k*2+1, l, (l+r)/2);
        add(a, b, x, k*2+2, (l+r)/2, r);
    }
}

ll sum(ll  a, ll  b, ll  k, ll  l, ll  r){
    
    if(b <= l || r <= a){
        return 0;
    }
    else if(a <= l && r <= b){
        return data[k] * (r-l) + datb[k];
    }
    else{
        ll res = (min(b, r) - max(a, l)) * data[k];
        res += sum(a, b, k*2+1, l, (l+r)/2);
        res += sum(a, b, k*2+2, (l+r)/2, r);
        return res;
    }
}

int main(){
    
	int n, k;
	
	while(cin >> n >> k, (n||k)){
    	
		CLR(data);
		CLR(datb);

	    for(int i=0; i<n; ++i){
			int a;
			scanf("%d", &a);
  			add(i, i+1, a, 0, 0, n);
		}
    
		ll ma = LLONG_MIN;

		for(int i=0; i<n-k; ++i){ 
			ma = max(ma, sum(i, i+k, 0, 0, n));
   	 	}
   	 
		cout << ma << endl;
	}

    return 0;
}

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

int main(void)
{
	int n,m,a;

	
	while(cin >> n >> m, n | m){
		int d[100001] = {};
		cin >> d[0];
	
		for(int i = 1; i < n; i++){
			cin >> a;
			d[i] += d[i-1] + a;
		}
		int MAX = 0;
		for(int i = 0; i < n - m; i++){
			if(d[i+m] - d[i] > MAX)
				MAX = d[i+m] - d[i];
		}
		cout << MAX << endl;
	}

	return 0;
}

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

int main(){
    int n,a[100001]={0},k,sum,p;
int i,j,h;
while(1){
cin>>n>>k;
if(n==0&&k==0)break;
cin>>a[1];
for(i=2;i<=n;i++){
	cin>>a[i];
	a[i]+=a[i-1];
}
sum=a[k];
for(i=k+1;i<=n;i++){
    sum=max(sum,a[i]-a[i-k]);
	}
cout<<sum<<endl;
}
return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main() {
    int n, k;
    while (cin >> n >> k) {
        if (n == 0) break;
        vector<ll> a(n);
        rep(i, n) cin >> a[i];
    
        vector<ll> s(n+1);
        rep(i, n) s[1+i] += s[i] + a[i];
        
        ll ans = -INF;
        for(int i = 0; i <= n-k; i++) {
            ll val = s[k+i] -s[i];
            if (ans < val) ans = val;
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int *a, *a2, m, n, t1;
	
	while(1){
		cin >> n >> m;
		if(n == 0){
			break;
		}
		
		a = (int *)calloc(n-m+1, sizeof(int));
		a2 = (int *)calloc(n, sizeof(int));
		
		for(int i = 0; i < n; i++){
			cin >> t1;
			a2[i] = t1;
		}
		
		for(int i = 0; i < m; i++){
			a[0] += a2[i];
		}
		
		for(int i = 0; i < n-m; i++){
			a[i+1] += (a2[m+i] + a[i] - a2[i]);
		}
		
		sort(a, a+(n-m+1));
		cout << a[n-m] << endl;
		
		free(a2);
		free(a);
	}
	
	return 0;
}

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

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

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

int n = 0;
int k = 0;
int a[100020] = {0};
int table[100020] = {0};

bool input() {
  cin >> n >> k;
  if (!n && !k) return false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    table[i+1] = a[i] + table[i];
  }
  return true;
}

int solve() {
  int Max = -1001001001;
  for (int i = 0; i < n-k; i++) {
    Max = max(Max, table[i+k]-table[i]);
  }
  return Max;
}

int main() {
  while(input()) {
    printf("%d\n", solve());
  }
  return 0;
}

C++: //include----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n, m, k;
VI a, b, c;
#define mod 1000000007
//function-------------------------------------------------------------------------------------------------------------------- 
int main() {
	while ( true ) {
		scanf( "%d %d", &n, &m );
		if ( !n && !m ) {
			return 0;
		}
		int e = 0;
		rep( i, n ) {
			scanf( "%d", &k );
			a.push_back( k );
			e = max( e, k );
		}
		int mx = 0;
		rep( i, n - m + 1 ) {
			int d = 0;
			rep( j, m ) {
				d += a[ i + j ];
				if ( mx >= d + e * ( m - j - 1 ) ) {
					break;
				}
			}
			mx = max( mx, d );
		}
		printf( "%d\n", mx );
		a = VI();
	}
	return 0;
}