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 <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60; //仮想的な無限大の値
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // 入力
    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<int> 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];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
    return 0;
}

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

int main(void)
{
    int n, k;
    while(1) {
        scanf("%d %d", &n, &k);
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        int ans, sum;
        ans = -114514;
        for(int i=0; i<n-k+1; i++) {
            sum = 0;
            for(int j=i; j<i+k; j++) {
                sum += a[j];
            }
            ans = max(ans, sum);
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

int main(){
  long long n,k,ans=0;cin>>n>>k;
  long long a[n];for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n-k+1;i++){
    long long temp=0;
    for(int j=i;j<i+k;j++){
      temp+=a[j];
    }
    ans=max(temp,ans);
  }
  cout<<ans<<endl;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
  cin >> n >> k;
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    cin >> set[i];
  }

  for(int i=1;i<n-1;i++){
    if(set[i-1]+set[i]+set[i+1]>max) max=set[i-1]+set[i]+set[i+1];
  }
  cout << max << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using P = std::tuple<int,int>;
using ll = long long;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}

template <typename T>
using F2 = std::function<T(T,T)>;

template <typename T, int N, typename F = std::plus<T>>
    struct SegmentTree{
        SegmentTree(T u, F f = F()){
            size = 1;
            while(size < N){
                size <<= 1;
            }

            unit = u;
            func = f;
            
            init();
        }
        void init(){
            for(int i=0;i<size;++i){
                data[i+size] = unit;
            }
            
            for(int i=size-1;i>0;--i){
                data[i] = func(data[i*2], data[i*2+1]);
            }
        }
        void update(int k, int v){
            k += size;
            data[k] = v;
            
            while(k > 1){
                k >>= 1;
                data[k] = func(data[k*2], data[k*2+1]);
            }
        }
        inline T query(int l, int r){
            return _query(l, r, 1, 0, size);
        }
        T _query(int a, int b, int k, int l, int r){
            if(b <= l || r <= a){return unit;}
            if(a <= l && r <= b){return data[k];}
            int mid = (l + r) >> 1;
            return func(_query(a, b,   2*k,   l, mid),
                        _query(a, b, 2*k+1, mid, r  ));
        }
        
        T unit, data[N*4];
        int size;
        F func;
    };

SegmentTree<ll, 100000> segtree(0);

int main(){
    //*
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    /*/
      /*/

    int N, K;
    while(true){
        std::cin >> N >> K;

        if(N == 0 && K == 0){break;}

        segtree.init();
        
        for(int i=0;i<N;++i){
            int a;
            std::cin >> a;

            segtree.update(i, a);
        }

        ll res = -1001001001001001001ll;
        for(int i=0;i+K<=N;i++){
            res = max(res, segtree.query(i, i+K));
        }

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

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

int main( void )
{
	int n, k;
	while ( cin >> n >> k && n > 0 && k > 0 )
	{
		vector <int> a( n+1, 0 );
		vector <int> dp( n+1, 0 );

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

		for ( int i = 1; i < n+1; i++ )
			dp[i] = dp[i-1] + a[i];

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

		cout << maxv << endl;

	}
}

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



int main(){
        int n, k,max,temp,num;
        while(true) {  //ベクターに格納
                cin >> n>>k;
                if(n==k!=0) break;
                vector<double> v;
                for(int i=0;i<n;i++){
                  cin>>num; //入力をnumに代入
                  v.push_back(num); //ベクターvにプッシュ
                }

                max=0;
                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 <iostream>
#include <cstdlib>
using namespace std;

#define MAX_N 100010
int N, K;
int S[MAX_N];

int main() {
  while (true) {
  cin >> N >> K;
  if (N == 0 && K == 0) break;
  int ans = INT_MIN;
  for (int i=0; i<N; i++) cin >> S[i];

  for (int i=0; i<=N-K; i++) {
    int t = 0;
    for (int j=0; j<K; j++) t += S[i+j];
    ans = max(ans, t);
  }
  cout << ans << "\n";
  }
  return 0;
}

C++: /*
	0516:Maxinum Sum
*/
#include	<iostream>
#include	<vector>
#include	<algorithm>

using namespace std;

int main(void) {
	while(1) {
		int n, k;
		cin >> n >> k;
		if(n == 0 && k == 0) { break; }
		
		vector<int> inputs(n);
		
		for( int i = 0; i < (int)inputs.size(); i++ ) {
			cin >> inputs[i];
		}
		int maxNum = 0, num;
		for( int i = 0; i < (int)inputs.size() - (k - 1); i++ ) {
			if(i == 0) {
				maxNum = inputs[i] + inputs[i+1] + inputs[i+2];
			} else {
				maxNum = max(maxNum, inputs[i] + inputs[i+1] + inputs[i+2]);
			}
		}
		
		cout << maxNum << endl;
		
	}
	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);
        for(int i=0; i<n; i++) cin >> a[i];
        int ans=0;
        for(int i=0; i<k; i++) ans += a[i];
        int mx=ans;
        for(int i=1; i<n-k+1; i++){
            mx=mx+a[k-1+i]-a[i-1];
            ans=max(ans, mx);
        }
        cout << ans << endl;
    }
}