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<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  while(true){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n==0&&k==0) return 0;
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    int sum = 0,ans = 0;
    for(int i=0;i+k<=n;i++){
      if(i==0){
        for(int j=0;j<k;j++) sum += a[i+j];
        ans = sum;
      }else{
        sum = sum - a[i-1] + a[i+k-1];
        ans = max(ans,sum);
      }
    }
    printf("%d\n",ans);
  }
}

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)

const int INF = 1 << 24;

typedef unsigned long long ull;

const int MAX_N = 1 << 18;

class SegmentTree{
public:
    SegmentTree(int n){
        size = 1;
        while(size < n){
            size *= 2;
        }

        REP(i, 2*n-1){
            data[i] = 0;
        }
    }

    void push(int k, int v){
        k += size - 1;
        data[k] = v;

        while(k > 0){
            int parent = (k - 1) / 2,
                c1 = parent * 2 + 1, c2 = parent * 2 + 2;

            data[parent] = data[c1] + data[c2];
            k = parent;
        }
    }

    int query(int l, int r){
        return _query(l, r, 0, 0, size);
    }

    int _query(int l, int r, int k, int a, int b){
        if(r <= a || b <= l){return 0;}

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

private:
    int data[MAX_N], size;
};

int main(){
    int N, K;
    while(std::cin >> N >> K, N){
        SegmentTree st(N);

        REP(i, N){
            int n;
            std::cin >> n;

            st.push(i, n);
        }

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

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

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n, m, s[10000000], k[10000000], MAX;
int main() {
	while (true) {
		MAX = -2000000000;
		cin >> n >> m;
		if (!n) { break; }
		for (int i = 1; i <= n; i++) {
			cin >> s[i];
			k[i] = k[i - 1] + s[i];
		}
		for (int i = 1; i <= n - m; i++) {
			MAX = max(MAX, k[i + m] - k[i]);
		}
		cout << MAX << endl;
	}
}

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

using namespace std;

typedef long long ll;

int a[1000000];

int main()
{
    int n, k;
    while(cin >> n >> k && n && k) {
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        ll pre = 0;
        for(int i = 0; i < k; i++) {
            pre += a[i];
        }
        
        ll ret = pre;
        for(int i = 0; i < n - k; i++) {
            pre = pre - a[i] + a[k + i];
            ret = max(ret, pre);
        }
        
        cout << ret << endl;
    }
}

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

unsigned long long int n, k, i, j, a[MAX_N], max = 0, 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<stdio.h>

long long int re[100001];

int main(){
	int n,k,i;
	long long c;
	re[0]=0;
	while(0<=scanf("%d%d",&n,&k)){
		if(n==0 && k==0)break;
		
		for(i=1;i<=n;i++){
			scanf("%lld",&c);
			re[i]=re[i-1]+c;
		}
		c=re[k];
		for(i=1;i+k-1<=n;i++){
			if(c<re[i+k-1]-re[i-1])c=re[i+k-1]-re[i-1];
		}
		printf("%lld\n",c);
	}
	return 0;
}

C++: #include <cstdio>

int main(){
	int n, k;
	int a[100000];
	int sum;
	int max;
	
	for(;;){
		max = -99999999;
		scanf("%d %d", &n, &k);
		if(n == 0 && k == 0) break;
		
		for(int i = 0; i < n; i++){
			scanf("%d", a[i]);
		}
	
		for(int i = 0; i < n - k; i++){
			sum = 0;
			for(int j = i; j < i + k; j++){
				sum += a[j];
			}
			if(max < sum) max = sum;
		}
	
		printf("%d\n", max);
	}
	
	return 0;
}

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

using namespace std;

int n,m,cnt;
int ans_max,an_max,an;
int a[100000];

int main(void){

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

    ans_max = -99999999;

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

    for( int i = 0 ; i <= n - m ; i++ ){
      an = 0;
      cnt = 3;
      for( int j = i ; j < i + 3 ; j++ ){
	an += a[j];
      }
      
      ans_max = max( ans_max , an );
      
    }

    cout << ans_max << endl;

  }
  return 0;
}

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

int main(){
  int n,k,x;
  vector<int> s;
  int start,end,ans=0,sum;
  
  while(1){
  
    cin>>n>>k;
    if(n==0 && k==0) break;
  
    for(int i=0;i<n;i++){
      cin>>x;
      s.push_back(x);
    }
    
    start=0;end=k;sum=0;
    for(int i=start;i<end;i++){
        sum+=s[i];
    }
    ans=max(ans,sum);
    
    while(end<n){
      sum+=s[end];
      sum-=s[start];
      ans=max(ans,sum);
      
      start++;end++;
    }
  
    printf("%d\n",ans);
    ans=0;sum=0;
    s.clear();
  }
  return 0;
}

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;
        }
        vector<int> vec(n);
        //vector<int> sum(n -k +1);
        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;
}