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 <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main(){
  int n, k;
  int N[100001], ans, sum;
  while(cin >> n >> k, n && k){
    memset(N, 10001, sizeof(N));
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }
    for(int i = 0 ; i < n - k ; i++){
      sum = 0;
      for(int j = i ; j < k + i ; j++){
	sum += N[j];
	//if(N[j+k-1] > 10000) break;
      }
      ans = max(ans, sum);
      //cout << ans << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int n, k, a[100000] = {};
	long long int sum = -10000000, tmp;
	while(cin >> n >> k){
		if(n == 0 && k == 0) break;
		for(int i = 0;i<n;i++){
			cin >> a[i];
			if(i < k) tmp += a[i];
		}
		for(int i = 0;i + k<n;i++){
			if(sum < tmp) sum = tmp;
			tmp = tmp - a[i] + a[i+k];
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,k,mx;
	while(cin>>n>>k,n){
		int a[100000]={0},b[100000]={0};
		rep(i,n)cin>>a[i]; rep(i,k)b[0]+=a[i]; mx=b[0];
		rep(i,n-k)b[i+1]=b[i]+a[i+k]-a[i],mx=mx>b[i+1]?mx:b[i+1];
		cout<<mx<<endl;
	}
	return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;

  int a[101010] = {0};

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

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

  cout << max_n << endl;
}
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n, k;
  cin >> n >> k;

  int a[101010] = {0};

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

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

  cout << max_n << endl;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
int a[MAXN], sum[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    	cin >> a[i];
    for (int i = 0; i < N; i++) 
    	sum[i+1] = sum[i]+a[i];
    int ans = -1e9-1;
    for (int i = 0; i+K <= N; i++) {
    	ans = max(ans, sum[i+K]-sum[i]);
    }
    cout << ans << endl;
    return 0;
}

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

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

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

	for(int n, k; cin >> n >> k, n;) {
		vector<int> a(n);
		for(int i = 0; i < n; ++i)
			cin >> a[i];

		int ans = 0, sum = 0;
		for(int i = 0; i < k - 1; ++i)
			sum += a[i];

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

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

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



int main(){
        int n, k;
        vector<double> v;
        cin >> n>>k;

        int num=0;
        for(int i=0; i<=n; i++) {  //ベクターに格納
                cin>>num; //入力をnumに代入
                v.push_back(num); //ベクターvにプッシュ
        }


        int max=0;
        int temp=0;
        for(int i=0; (i+k)<=n; i++) {
                for(int j=0; j<k; j++) {
                        temp+=v[i+j]; //tempにvのiからi+k番目までの総和を代入
                }
                //cout<<temp<<endl;
                if(temp>max) max=temp;  //tempが最も大きい数値ならmaxを更新
                temp=0; //tempの初帰化
        }
        cout<<max<<endl;
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j;while (1) {scanf("%d %d",&N,&K);if (!N || N==EOF) return 0;ans=-1000000007,j=0;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);}}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa, bool isBegin)
{
	int temp = 0;
	int i;
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa, 0);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0, 1));
	}
}

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

using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (!n && !k) return 0;
    int a[n];
    long long result = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        result += a[i];
    }
    for (int i = k; i < n; i++)
      result = max(result, result - a[i-k] + a[i]);
    cout << result << endl;
  }
}

C++: 

#include <iostream>

using namespace std;

int main() {
  int k, n;
  while (1) {
    cin >> n >> k;

    if ((k == 0 && n == 0)) {
      return 0;
    }
    int a[100000];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t > s) {
        s = t;
      }
    }
    cout << s << endl;
  }
  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;i++){
		if(sum[m+i]-sum[i]>max)
		max=sum[m+i]-sum[i];
	}
	cout<<max<<endl;
		sum.clear();
	}
	return 0;
}

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

int seq[100000];
int n,k;

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