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<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,n2[100001],n_sum[100001];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>n2[i];
    }
    n_sum[0]=0;
    for(int i=1;i<n;i++){
        n_sum[i]=n_sum[i-1]+n2[i];
    }
    int maxx=n2[0]-1;
    for(int i=k;i<n;i++){
        int sum=0;
        sum=n_sum[i]-n_sum[i-k];
        maxx=max(maxx,sum);
    }
    cout<<maxx<<endl;
}

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

int seq[100000];
int n,k;

int req(int i)
{
	int sum = 0;
	for(int j=0;j<k;j++){
		sum += seq[i+j];
	}
	return sum;
}
int main()
{
	while(cin >> n >> k){
		if(n==0&&k==0)
			break;
		for(int i=0;i<n;i++){
			cin >> seq[i];
		}
		int rem=-100000000;
		for(int i=0;i<n-k+1;i++){
			rem = max(rem,req(i));
		}
		cout << rem << endl;
	}
	return 0;
}

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

int n, k;
int a[100000];
int ra[100001];	//ra[i] = a[0] + ??? + a[i-1]

int main() {
	while (cin >> n >> k) {
		if (!n) { break; }
		ra[0] = 0;
		for (int i = 0; i < n; i++) {
			ra[i+1] = ra[i] + a[i];
		}

		int ans = -1000000001;
		for (int i = 0; i < n - k + 1; i++) {
			//a[i] + ??? + a[i+k-1]
			ans = max(ans, ra[i+k] - ra[i]);
		}

		cout << ans << endl;
	}
	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 );
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n=0, k=0 ,ans;
double a[100001] = {}, b[100001] = {};
int main(){
	while (true){
		n = 0; k = 0;
		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[x+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];
				ans = max(b[i],b[i-1]);
			}
		cout << ans << endl;
		}	
	return 0;
}

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

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[100000];
	for(int i=0;i<100000;i++) wa[i] = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		for(int j=0;j<k;j++){
			wa[i+j] += x;
		}
	}
	cin >> x >> x;
	for(int i=0;i<n;i++){
		if(maxnum < wa[i]) maxnum = wa[i];
	}
	cout << maxnum;
}

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

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;
	while (cin >> n >> k, n) {
		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 main(){

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

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

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

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

using namespace std;

int a[100000 + 1];
int s[100000 + 1];

int main() {

	int n, k;
	int i, j, l;
	int sum = 0, asus = 0;

	while (true) {

		memset(s, 0, sizeof(s));
		memset(a, 0, sizeof(a));

		cin >> n >> k;
		if (n == 0 && k == 0) return 0;

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

		for (i = 0; i < n-k; ++i) {
			for (j = 0; j < k; ++j) {

				sum += a[i + j];
			}
			asus = max(asus, sum);
			sum = 0;
		}

		cout << asus << endl;
	}
}