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<algorithm>
#include<string>
#include <vector>

using namespace std;

int main(){

	int n,k,a[100000],sum,ans,i;

	while(cin>>n>>k,n||k){

	sum=0;

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

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

    ans=sum;
    i=0;

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

    cout<<ans<<endl;
	}
}

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

int main(){
	int n,k,i,j,l;
	int a[100000];
	int Smax,S;
	while(l<5){
		cin>>n;
		cin>>k;
		if(n==0){break;}
		
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		for(i=0;i<n-k;i++){
			S=0;
			for(j=i;j<i+k;j++){
				S+=a[j];
			}
			if(Smax<S){Smax=S;}
		}
		
		cout<<Smax<<endl;
		
		l++;
	}
		return 0;
		
}

C++: #include <stdio.h>
int main(){
	int n,k,i,max=0;
	int x[100001];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)[
	scanf("%d",&x[i]);
}
for(i=0;i<k;i++){
	max+=x[i];
}
	for(i=0;i<n-k;i++){
		if(x[i]<x[i+k]){
			max-=x[i];
			max+=x[i+k];
		}}
		printf("%d\n",max);
		return 0;
		}

C++: #include<bits/stdc++.h>
using namespace std;
int N,K;
int a[100000];


int main()
{
    while(scanf("%d%d",&N,&K),N||K){
        for(int i=0;i<N;i++)scanf("%d",&a[i]);

        int sum=0;
        for(int i=0;i<K;i++)sum+=a[i];

        int ma=sum;
        for(int i=K;i<N;i++){
            sum-=a[i-K];
            sum+=a[i];
            ma=max(ma,sum);
        }
        printf("%d\n",ma);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    while(cin >> n >> k and n and k) {
        vector<int> a(n + 1);
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int ans = lim<int>::min();
        int s = 0;
        for(int i = 1; i <= n; i++) {
            s += a[i];
            if(i >= k) {
                s -= a[i - k];
                ans = max(ans, s);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main()
{
  long long n,k;
  while(cin>>n>>k){
    if (n == 0) break;
    vector<long long> a(n);
    vector<long long> s(n+1);
    for(long long i=0; i<n; i++){
      cin>>a[i];
    }
    for(long long i=0; i<n; i++){
      s[i+1]=s[i]+a[i];
    }
    long long ans=-1e9;
    
    for(long long i=0; i<=n-k; i++){
      long long val =s[i+k]-s[i];
      if(ans<val) ans=val;
    }
    cout<<ans<<endl;
  }
  
}

C++: #include<cstdio>

int main()
{
    int n,m,a[100008];
    while(~scanf("%d%d",&n,&m))
    {
        if(!n&&!m) break;
        int sum = 0,cap = 0,temp = -2000000001;
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        for(int i=0;i<n;i++){
            if(cap!=m){ sum += a[i]; cap++; }
            else sum += a[i]-a[i-3];
            if(sum>temp) temp=sum;
        }
        printf("%d\n",temp);
    }
    return 0;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	while (true) {
		int n, k;
		cin >> n >> k;
		if (n == k&&k == 0) {
			return 0;
		}
		vector<int> a;
		REP(i, n) {
			int b;
			cin >> b;
			a.push_back(b);
		}
		long long ans = -1000000000000;
		long long tmp = 0;
		for (int i = 0;i < k;++i) {
			tmp += a[i];
		}
		ans = tmp;
		for (int i = k;i < n;++i) {
			tmp += a[i];
			tmp -= a[i - k];
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}
}

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

int main(){
    int n,k;
    while(cin>>n>>k){
        int total[100010]={0},ip[100010]={0};
        if(n==0 && k==0)break;
        for(int i=0;i<n;i++){
            cin>>ip[i];
            if(i==k-1){
                for(int j=0;j<k;j++){
                    total[i]+=ip[i-j];
                }
            }
            if(i>k-1){
                total[i]=total[i-1]-ip[i-k]+ip[i];
            }
        }
        sort(total, total+n, greater<int>());
        cout<<total[0]<<endl;
    }
    return 0;
}

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

int main(){
	while(1){
		long n, k;
		long s[100001]; //i番目までの和
		s[0]=0;
		
		scanf(" %ld %ld", &n, &k);
		if(n==0) break;
		for(long i=0; i<n; ++i){
			int a;
			scanf(" %d", &a);
			s[i+1] = s[i]+a;
		}
		
		long max=-1500000000;
		for(int i=1; i+k<=n; ++i){
			long tmp=s[i+k]-s[i];	
			if(tmp>max) max=tmp;
		}
		
		printf("%ld\n", max);
	}
}

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

int main(){
  int numn,lisn,num;
  vector<int> outp;
  int outn = 1;
  for(int l = 0;;l++){
    cin >> numn >> lisn;
    if(numn == 0 && lisn == 0)break;
    outp.resize(l+1,0);
    vector<int> lists(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num;
      lists[n] = num;
    }
    for(int k = 0;k<numn-2;k++){
      outn = lists[k] + lists[k + 1] + lists[k + 2];
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << "";
  }
}

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

int main() {
    int n,k;
    while(true){
        cin>>n>>k;
        if(n==0)break;
        vector<int> a(n+1,0);
        for (int i = 1; i <= n; ++i) {
            cin>>a[i];
            a[i]+=a[i-1];
        }
        int ans=0;
        for (int i = 0; i+k < n; ++i) {
            ans=max(ans,a[i+k]-a[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int N, K;
  while (cin >> N >> K) {
    if (N == 0) break;

    // 数列読み込み
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // 累積和を前計算
    vector<long long> s(N+1, 0);
    for (int i = 0; i < N; ++i) s[i + 1] = s[i] + a[i];

    long long res = -INF;
    for (int i = 0; i <= N - K; ++i) {
      long long val = s[K+i] - s[i];
      res = max(res, val);
    }

    cout << res << endl;
  }

  return 0;
}