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 <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int n,k;
    while (cin >> n >> k) 
    {
        if (n == 0 && k==0) 
        {
            break;
        }
        vector<int> vec(n);
        int sum_max=0;
        int j;
        int sum=0;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];

            if (k  == i + 1) 
            {
                for (j = 0; j < k; j++) 
                {
                    sum += vec[i - j];
                }
                cout << endl;
                sum_max = max(sum ,sum_max);
                sum -= vec[i-k+1];
            }
            else if (k  < i + 1) 
            {
                sum += vec[i];
                sum_max = max(sum ,sum_max);
                sum -= vec[i-k+1];
            }
        }
        cout << sum_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; }
		else{
			int i, inp;
			int *a;
			a = new int[n];

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

			int sum1 = 0, sum2 = 0, max = 0;

			for (i = 0; i<k; i++){ sum1 += a[i]; }
			max = sum1;

			for (i = k; i<n; i++){
				sum2 = sum1 + a[i] - a[i - k];
				if (sum2>max){ max=sum2; }
				sum2 = sum1;
			}

			cout << max << endl;

			delete[] a;
		}
	}
	return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    loop {
        int N = next<int>(), K = next<int>();
        if(!N && !K) break;
        auto A = next<vector<int>>(N);
        int ans, now = 0;
        times(K, i) {
            now += A[i];
        }
        ans = now;
        times(N - K, i) {
            now += A[K + i] - A[i];
            ans = max(ans, now);
        }
        cout << ans ln;
    }

    return 0;
}

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

using namespace std;

int n, k, r, i = 0, a[100000];
pair<pair<int,int>,long long int> b[100000];
long long int sorter[1000000];
long long int result[100];

int main()
{
	for (;; i++)
	{
		r = 0;
		cin >> n >> k;
		if (n == 0)
		{
			break;
		}

		for (int p = 0; p < n; p++)
		{
			cin >> a[p];
			b[p].first.first = p;
			b[p].first.second = p;
			b[p].second = a[p];
		}

		for (int p = 0; p < k-1; p++)//?¶?????????°
		{
			for (int q = 0; q < n + r; q++)
			{
				if (b[q].first.first == b[q + 1].first.first && b[q].first.second == b[q + 1].first.second)
				{
					b[q].first.first = 100001;
					r--;
					q--;
					sort(b, b + n);
					goto qwop;
				}
				else
				{
					if (b[q].first.first == 0)
					{
						b[q].second += a[b[q].first.second + 1];
						b[q].first.second++;
					}
					else if (b[q].first.second == n - 1)
					{
						b[q].second += a[b[q].first.first - 1];
						b[q].first.first--;
					}
					else if (a[b[q].first.second + 1] == a[b[q].first.first - 1])
					{
						b[k] == b[q];
						b[q].second += a[b[q].first.first - 1];
						b[q].first.first--;
						b[k].second += a[b[k].first.second + 1];
						b[k].first.second++;
						r++;
					}
					else if (a[b[q].first.second + 1] > a[b[q].first.first - 1])
					{
						b[q].second += a[b[q].first.second + 1];
						b[q].first.second++;
					}
					else if (a[b[q].first.second + 1] < a[b[q].first.first - 1])
					{
						b[q].second += a[b[q].first.first - 1];
						b[q].first.first--;
					}
				}
				qwop:;
			}
			sort(b, b + n);
		}

		for(int p = 0;p<n;p++)
		{
			sorter[p] = b[p].second;
		}

		sort(sorter,sorter+n+r,greater<int>());

		result[i] = sorter[0];
	}
	for (int p = 0; p < i; p++)
	{
		cout << result[p] << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
	int n,k;

	while (1) {
		cin >> n >> k;

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

		vector <int> a (n + 1, 0 );
		int res = 0, s = 0;

		for (int i = 1; i <= n; ++i){
			cin >> a[i];
			if (i < k ){
				s += a[i];
			}else if (i == k ){
				s += a[i];
				res = s;
			}else{ // if (i > k ){
				s -= a[i-k];
				s += a[i];
				res = max (res , s );
			} // end if				
		} // end for

		cout << res << endl;
	} // end loop
		
	return 0;
}

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

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