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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int inp[1000000];
	
int main() {
	int n,m;
	while(n=in(),m=in()){
		int i;
		for(i=0;i<n;i++){
			inp[i]=in();
		}
		Int max;
		Int sum=0;
		int k;
		for(k=0;k<m;k++){
			sum+=inp[k];
		}
		max=sum;
		for(i=0;i<=n-m;i++){
			if(max<sum)max=sum;
			sum-=inp[i];
			sum+=inp[i+m];
		}
		cout<<max;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(void){
	int n=0, k=0;
	int *a;
	long sum  = 0;
	long msum = 0;

	scanf("%d %d", &n, &k);
	a = (int*)malloc(sizeof(int) * n);
	for(int i=0; i<n; ++i){
		scanf("%d", a+i);
	}

	for(int i=0; i<k; ++i){
		sum += a[i];
	}
	msum = sum;

	for(int i=0; k<n; ++i,++k){
		sum = sum - a[i] + a[k];
		if(sum > msum){
			msum = sum;
		}
	}
	printf("%d\n", msum);
	getchar();getchar();
	free(a);
	return 0;
}

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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) elems.push_back(item);
      item.clear();
    }
    else item += ch;
  }
  if (!item.empty()) elems.push_back(item);
  return elems;
}

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

signed main()
{
  int n, m;

  while (cin >> n >> m, n + m){
    int a[n], maxsum = 0;

    rep(i, n) a[i] = in();
    reps(i, 2, n) maxsum = max(maxsum, a[i - 2] + a[i - 1] + a[i]);
    print(maxsum);
  }

  return (0);
}

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

int main(){

    while(1){
        int n, k; cin >> n >> k;
        if(n == 0) break;

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

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

        cout << ans << endl;
    }

    return 0;
}

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

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

int main(void){
  int n , k;
  while(cin>>n>>k,n+k){
  vector<int> in(n,0);
  vector<int> dp(n,0);
  for(int i = 0 ; i < in.size() ; i ++) 
    cin>>in[i];
  int res = 0;
  for(int i = 0 ; i < in.size() - k ; i ++){
    for(int j = i ; j < i + k ; j ++){
      dp[i] += in[j]; 
    }
    res = max(res,dp[i]);
  }
  
  cout<<res<<endl;
  }
}

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

using namespace std;

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

		m[0] = 0;
		for (int i = 0;i < n;i++)
			m[i + 1] = m[i] + a[i];

		s = 0;
		for (int i = 1;i +k<=n;i++)
		{
			b = m[i + k ] - m[i ];
			if (s < b) 
				s = b;
		}

	}
	cout << s << endl;
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[])
{
  int n, k;
  cin >> n >> k;
  do {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    // 累積和を計算
    vector<int> com_sums(n + 1, 0);
    for (int i = 0; i < a.size(); i++) {
      com_sums[i + 1] = com_sums[i] + a[i];
    }

    int result = com_sums[k] - com_sums[k - k];
    for (int i = k + 1; i < a.size(); i++) {
      result = max(result ,com_sums[i] - com_sums[i - k]);
    }
    cout << result << "\n";

    cin >> n >> k;
  } while(n != 0);

  return 0;
}

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

int main()
{
int n,k;
cin >> n >> k;
while(n!=0||k!=0){
  int i=0, a[n], S[n-1];
  S[0] = 0;
  while(i < n){
    cin >> a[i];
    if (i>=1)
      S[i] = S[i-1]+a[i-1];
    i++;
  }
  i = 0;
  int m = S[k]-S[0];
  while(k+i<n){
    if (m < S[i+k]-S[i])
      m = S[i+k]-S[i];
    i++;
  }
  cout << m << endl;
cin >> n >> k;
}}

C++: #include<iostream>

int main(){

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

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

		int data[100001] = { 0 };
		for (int i = 1; i <= n; i++){
			std::cin >> data[i];
		}
		for (int i = 1; i <= n; i++){
			data[i] += data[i - 1];
		}

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

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