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 main() {
	while (1) {
		int n, k, a[100005] = { 0 }, m = -9999999, dp[100005] = { 0 };
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < k; i++) {
			dp[0] += a[i];
		}
		for (int i = 1; i < n - k + 2; i++) {
			dp[i] = dp[i - 1] - a[i - 1] + a[i + k - 1];
		}
		for (int i = 0; i < n - k + 1; i++) {
			//cout << dp[i] << endl;
			if (m < dp[i]) m = dp[i];
		}
		cout << m << endl;
	}
	return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define x first
#define y second


int main() {
    int n,k;
    while(cin>>n>>k){
        if(n==0 && k==0)break;
        int num[200000]={};
        rep(i,n) cin>>num[i];
        
        int now=0;
        rep(i,k){
            now+=num[i];
        }
        int maxi=-1;
        for(int i=1;i<n-k+1;i++){
            now-=num[i-1];
            now+=num[i+k-1];
            maxi=max(now,maxi);
        }
        cout<<maxi<<endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

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();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	for(int n, k; cin >> n >> k && n && k;) {
		vector<int> arr(n);
		vector<int> sum(n);
		rep(i,n) cin >> arr[i];
		rep(i,k) sum[k-1] += arr[i];
		for(int i = k; i < n; i++) {
			sum[i] = sum[i - 1] + arr[i] - arr[i - k];
		}
		cout << *max_element(all(sum)) << endl;
	}
	return 0;
}

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

int main(){
while (true){
int n=0, k=0;
double 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<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(1){
	int n,k,x=0,ma=0;
	cin>>n>>k;
		if(n==0 && k==0)
		break;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-k;i++){
		x=0;
		for(int j=0;j<k;j++){
			x+=a[i+j];
		}
		ma=max(ma,x);
	}
	cout<<ma<<endl;
	}
return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
    int n, m, a, b;
    int nums[5];
    cin >> n >> m;
    while(cin >> a >> b) {
        int i = 0;
        if(a == 0 && b == 0) {
            break;
        }
        nums[i] = a;
        i++;
    }
    int max = 0;
    for(int i = 0; i < m; i++) {
        i += nums[i];
    }
    for(int i = 1; i < n - m + 1; i++) {
        int sum = 0;
        int k = i;
        for(int j = 0; j < m; j++) {
            sum += nums[k + j];
        }
        if(sum > max) {
            max = sum;
        }
    }
    cout << max << endl;
}

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}
		
		printf("%d\n", max);
	}
	
	return (0);
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	vector<int> sum;
	int n,m,x,max;
	while(cin>>n>>m,n||m){
	cin>>x;
	sum.push_back(0);
	sum.push_back(x);
	max=-1000000;
	for(int i=2;i<=n;i++){
		cin>>x;
		sum.push_back(sum[i-1]+x);
	}
	for(int i=0;i<n-m+1;i++){
		if(sum[m+i]-sum[i]>max)
		max=sum[m+i]-sum[i];
	}
	cout<<max<<endl;
		sum.clear();
	}
	return 0;
}

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

using namespace std;

int main() {
    while(true) {
        int n, k;
        cin >> n >> k;
        int sum = 0;
        int ans = 0;
        queue<int> q;
        for(int i = 0; i < n; ++i) {
            int num;
            scanf("%d", &num);

            sum += num;
            if(i == k-1) ans = sum;
            if(i >= k) {
                sum -= q.front();
                q.pop();
                ans = max(ans, sum);
            }
            q.push(num);
        }

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

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

int main(void)
{
  ios::sync_with_stdio(false);
  int n, k;
  int max;
  int sum;
  while (true)
  {
    cin >> n >> k;
    if ( n == 0 && k == 0 ) break;

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

    max = -999999;
    for (int j = 0; j < n-k+1; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    delete[] num_sequence;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int num[100100];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<100001;i++){
              num[i]=0;
              if(num[i+1]==0)braek;
         }
         cin>>n>>m;
         if(n==0&&m==0)break;
         for(int i=0;i<n;i++) cin>>num[i];
         for(int i=0;i<n-m;i++){
              int min=0;
              for(int j=i;j<i+m;j++)min+=num[j];
              if(ans<min)ans=min;
         }
         cout<<ans<<endl;
         ans=0;
    }
    return 0;
}