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 <vector>
using namespace std;

int main(){
  int serchn,numn,gh;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0)break;
    outp.resize(a+1);
    vector<int> num(numn);
    for(int n = 0;n<numn;n++){
      cin >> num[n];
    }
    for(int n = 0;n<numn - serchn + 1;n++){
      gh = 0;
      for(int g = 0;g<serchn;g++){
        gh += num[g+n];
      }
      if(outp[a] < gh)outp[a] = gh;
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  return 0;
}

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

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

    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 <iostream>
using namespace std;

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

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

int main() {
	int a[100000];int n,m;int b[100000];int p=0;
	cin >> n >> m;
	for(int i = 0;i<n;i++){
		cin >> a[i];
	}
	for(int i = 0;i<100000;i++){
		b[i]=0;
	}
	for(int i = 0;i<n-m;i++){
		if(a[i]>a[i+m]){
			for(int k = i;k<i+m;k++){
				b[p]+=a[k];
			}
			p++;
		}
	}
	for(int k = n-m;k<n;k++){
				b[p]+=a[k];
	}
	for(int i = 1;i<100000;i++){
		if(b[0]<b[i]){b[0]=b[i];}
	}
	cout << b[0]<<endl;
	return 0;
}

C++: #include <stdio.h>

#define REV_INF (1 << 31)

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

C++: #include<cstdio>
using namespace std;
int main(){
    int n,k;
    int s = 0;
    int a[10000] = {0};
    for(;;){
        scanf("%d%d",&n,&k);
        if(n == 0&&k == 0)break;
        for(int i = 0;i < n; i++){
            scanf("%d",&a[i]);
        }
        int x = 0;
        for(int i = 0;i < k; i++){
            x += a[i];
        }
        s = x;
        for(int i = 0;i < (n-k); i++){
            x -= a[i];
            x += a[i+k];
            if(s < x)s = x;
        }
        printf("%d\n",s);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, K;

class SparseTable{
public:
    SparseTable(){}
    SparseTable(int *a, int n){
        init(a, n);
    }
    void init(int *a, int n){
        size = n;

        REP(i, size){
            table[i][0] = a[i];
        }

        int step = 1, done = 1;
        while(done < size){
            for(int i=0;i+done<size;i++){
                table[i][step] = table[i][step-1] + table[i+done][step-1];
            }
            ++step;
            done *= 2;
        }
    }
    int query(int l, int r){
        int n = r - l, step = 0, res = 0;
        while(n > 0){
            if(n & 1){res += table[l][step]; l += 1 << step;}
            n >>= 1;
            ++step;
        }
        return res;
    }
private:
    static const int MAX_N = 100000, MAX_LOG_N = 17;
    int table[MAX_N][MAX_LOG_N+1], size;
};

SparseTable st;
int A[100000];

int main(){
    while(std::cin >> N >> K, N){
        REP(i, N){
            std::cin >> A[i];
        }
        st.init(A, N);

        int res = -INF;
        for(int i=0;i+K<=N;i++){
            res = std::max(res, st.query(i, i+K));
        }

        std::cout << res << std::endl;
    }
}

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;
        }
        int vec[n];

        int sum=0;
        int sum_max=0;
        int input;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];
        }
        for (int i = 0; i < n - k + 1; i++) 
        {
            sum=0;
            for (int j = 0; j < k; j++) 
            {
                sum += vec[i + j];
            }
            if (sum_max < sum) 
            {
                sum_max = sum;
            }
        }
        cout << sum_max << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define loop(times) for(int i=0;i<(times);i++)

using namespace std;

int main() {
    while(1<2){
    int n,K;
    long long max;
    cin>>n>>K;
    if(n==0&&K==0)break;
    int S[n];
    int a[n];
    S[0]=0;
    loop(n) cin>>a[i];
    loop(K) S[0]+=a[i];
    max=S[0];
        
    for(int j=1;j<n-K+1;j++){
    S[j]=S[j-1]+a[j+K-1]-a[j-1];
    if(max<=S[j])max=S[j];
    }
        
    cout<<max<<endl;
    }
}

C++: #include <cstdio>

using namespace std;

int n=1,k=1,s,smax;
int a[100000];
int s1,s2;

int main(){
	while(n!=0&&k!=0){
	scanf("%d %d\n",&n,&k);
	if(n==0&&k==0) break;
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
	printf("%d\n",smax);
	}
	return 0;
}

C++: #include<stdio.h>
int P[100001];

int main(){

int n,k;
int x,x1,x2,x3;
while(1){
scanf("%d %d",&n,&k);
if(n==0&&k==0)break;
int s=0,max=0;

for(int i=0;i<n;i++)
{scanf("%d",&P[i]);}

for(int i=0;i<=n-k;i++)
{
for(int j=i;j<k+i;j++)
s+=P[j];

if(s>max)max=s;s=0;
}
printf("%d\n",max);
}
return 0;
}