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>

using namespace std;

int main()
{
  int n, m, a[100000], t, s;

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

    t = s = 0;
    for(int i = 0; i < m; i++){
      t += a[i];
    }
    s = t;
    for(int i = m; i < n; i++){
      t += (a[i] - a[i-m]);
      if(s < t){
	s = t;
      }
    }
    cout << s << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int main() {
	int n, k;
	while (scanf("%d %d",&n,&k)&&n!=0) {
		vector<int> a(n);
		for (int i=0; i<n; i++) scanf("%d",&a[i]);
		int max=0;
		for (int i=0; i<n-k; i++) {
			int tmp=0;
			for (int j=i; j<i+k; j++) {
				tmp+=a[j];
			}
			if (tmp>max) max=tmp;
		}
		printf("%d\n",max);
	}
}

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

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

C++: #include<iostream>

const int MAX_N = 1 << 17, INF = 1 << 24;

class SegmentTree{
public:
	SegmentTree(int _n){
		n = 1;
		while(n < _n)n *= 2;
		for(int i=0;i<2*n-1;i++){
			data[i] = 0;
		}
	}

	void add(int k, int a){
		k += n - 1;
		data[k] = a;
		while(k > 0){
			k = (k-1) / 2;
			data[k] = data[k*2+1] + data[k*2+2];
		}
	}

	int calculate(int a, int b){
		return _calculate(a, b, 0, 0, n);
	}
private:
	int data[MAX_N];
	int n;
	int _calculate(int a, int b, int k, int l, int r){
		if(r <= a || b <= l)return 0;

		if(a <= l && r <= b)return data[k];
		else{
			int l_child = _calculate(a, b, 2*k+1, l, (l+r) / 2),
				r_child = _calculate(a, b, 2*k+2, (l+r) / 2, r);
			return l_child + r_child;
		}
	}
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		SegmentTree st(n);
		for(int i=0;i<n;i++){
			int a_i;
			std::cin >> a_i;
			st.add(i, a_i);
		}

		int res = -INF;

		for(int i=0;i+k-1<n;i++){
			res = std::max(res, st.calculate(i, i+k));
		}

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

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

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

C++: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main(){
  int n,k;
  while(cin >> n >> k,n){
    vector<int> vec(n);
    REP(i,n) cin >> vec[i];
    int ans = 0;
    REP(i,k) ans += vec[i];
    int tmp = ans;
    FOR(i,k,n){
      tmp += vec[i];
      tmp -= vec[i-k];
      ans = max(ans,tmp);
    }
    cout << ans << 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; i++){
            if(max < sum[i]){
                max = sum[i];
            }
        }
        cout << max << endl;
    }
}

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

using namespace std;

int main() {
    while(true) {
        int a, b;
        cin >> a >> b;
        if(!a && !b) break;

        vector<vector<int> > dp(a, vector<int>(b, 0));
        dp[0][0] = 1;

        int n;
        cin >> n;
        while(n--) {
            int x, y;
            cin >> x >> y;
            --x; --y;
            dp[x][y] = -1;
        }
        for(int i = 0; i < a; ++i) {
            for(int j = 0; j < b; ++j) {
                if(dp[i][j] == -1) continue;
                if(i-1 >= 0 && dp[i-1][j] != -1) dp[i][j] += dp[i-1][j];
                if(j-1 >= 0 && dp[i][j-1] != -1) dp[i][j] += dp[i][j-1];
                if(i+1 < a && dp[i+1][j] != -1) dp[i][j] += dp[i+1][j];
                if(j+1 < b && dp[i][j+1] != -1) dp[i][j] += dp[i][j+1];
            }
        }

        cout << dp[a-1][b-1] << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
long su[100000010] = { 0 };
long sai;
int main()
{
	long n, k;
	long i, j;
	long a;
	while (cin >> n >> k, n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{
			cin >> a;
			su[i] = su[i - 1] + a;
		}
		sai = 0;
		for (i = k; i <= n; i++)
		{
			if (sai < su[i] - su[i - k])
			{
				sai = su[i] - su[i - k];
			}
		}
		cout << sai << endl;
	}
	return 0;
}

C++: #include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		scanf("%d %d",&a,&b);
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			scanf("%d",&d);
			e[c]=d;
		}
		for (int f=0;f<=a-b;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
			if (e[f]>=max) max=e[f];
		}
		printf("%d\n",max);
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i < n - k - 1; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
main(){
  int n,k,a;
  int node1=0,node2,max;
  int ruiseki[100001]={0};
  cin>>n>>k;
  node2=k;
  for(int i=1;i<=n;i++){
    cin>>a;
    ruiseki[i]=ruiseki[i-1]+a;
    if(i>=k){
      if(i==k){
	max=ruiseki[node2]-ruiseki[node1];
      }
      else if(max<ruiseki[node2]-ruiseki[node1]){
	max=ruiseki[node2]-ruiseki[node1];
      }
      node1++;
      node2++;
    }
  }
  cout<<max<<endl;
}