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,k;
cin >> n >> k;
while(n!=0||k!=0){
  int i=0, a[n], S[n-1];
  S[0] = 0;
  while(i < n){
    cin >> a[i];
    if (i>=1)
      S[i] = S[i-1]+a[i-1];
    i++;
  }
  i = 0;
  int m = S[k]-S[0];
  while(k+i<=n){
    if (m < S[i+k]-S[i])
      m = S[i+k]-S[i];
    i++;
  }
  cout << m << endl;
cin >> n >> k;
}}

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

int main(){

  int n,k;

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

    int a[100000] = {0},z = 0;

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

    for(int i=0;i<k;i++) z += a[i];

    for(int i=k;i<n;i++) z = max(z , z+(a[i]-a[i-k]));

    cout << z << endl; 
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int>in(n+1);
		rep(i,n)cin>>in[1+i];
		loop(i,1,1+n)in[i]+=in[i-1];
		int ma=-1e9;
		rep(i,n-m+1)ma=max(ma,in[i+m]-in[i]);
		cout<<ma<<endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
		int n, k;
		double a[100001] = {}, b[100001] = {}, ans;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int i = 1; i <= n; i++){
			for (int x = 0; x<k; x++){
				if (a[i + k] == 0) break;
				b[i] = a[i + x];
			}
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		cout << ans << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n = 0, k = 0;
int a[100001] = {}, b[100001] = {};
int ans;
int main(){
	while (true){
		n = 0; k = 0;
		ans = 0;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[x + 1];
		}
		ans = b[1];
		for (int i = 2; i <= n; i++){
			if ((i+k)==(n+1))	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			ans = max(b[i], ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	int n, m;
	while(scanf("%d %d", &n, &m)){
		if(n == 0 and m == 0) break;
		int array[MAX];
		fill(array, array + MAX, 0);
		for(int i = 0; i < n; i++) scanf("%d", &array[i]);
		
		int sum = 0, max = 0;
		for(int i = 0; i < n - m; i++){
			sum = 0;
			for(int j = i; j < i + m; j++){
				sum += array[j];
			}
			if(sum > max) max = sum;
		}
		printf("%d\n", max);
	}
	return 0;
}

C++: #include <stdio.h>

int a[100000],e[100000];
int main(){
	int b,c,d,f,g=-100000000;
	while(1){
		scanf("%d %d",&c,&b);
		if(c==0){
			return 0;
		}
		for(d=0;d<c;d++){
			scanf("%d",a[d]);
		}
		for(d=0;d<c-b;d++){
			for(f=0;f<b;f++){
				e[d]+=a[f];
			}
		}
		for(d=0;d<c-b;d++){
			if(g<=e[d]){
				g=e[d];
			}
		}
		printf("%d\n",g);
	}
}

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

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

		if (n==0&&k==0){ break; }
		else{
			int i, j, inp, max = 0;
			int *a;
			
			a = new int[n];

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

			for (i = 0; i < n - k + 1; i++){
				int sum = 0;

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

				if (sum > max){ max = sum; }
			}

			cout << max << endl;

			delete[] a;
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#define max(a,b) ((a)>=(b)?(a):(b))
int BIT[100001],n,k;
int sum(int i) {
	int s=0;
	while(i>0) {
		s+=BIT[i];
		i-=i&-i;
	}
	return s;
}
void add(int i,int x) {
	while(i<=n) {
		BIT[i]+=x;
		i+=i&-i;
	}
}
int main() {
	while(scanf("%d %d",&n,&k),n|k) {
		memset(BIT,0,sizeof(BIT));
		for(int i=1;i<=n;i++) {
			int a;
			scanf("%d",&a);
			add(i,a);
		}
		int mx=-1000000000;
		for(int i=1;i<=(n-k+1);i++) {
			mx=max(mx,sum(i+k-1)-sum(i-1));
		}
		printf("%d\n",mx);
	}
}

C++:     #include <iostream>
    using namespace std;
    #define rep(i, n) for(int i=0;i<(n);i++)
     
    int a[100000] = {};
    int s[100000] = {};
    int n, k, m;
     
    int main() {
     
    	while(cin>>n>>k, n|k) {
    		rep(i, n)cin>>a[i];
    		s[0] = 0;
    		rep(i, k)s[0]+=a[i];
    		rep(i, n-k)s[i+1]=-a[i]+s[i]+a[i+k];
    		m=s[0];
    		rep(i, n-k+1) {
    			if(m<s[i])m=s[i];
    		}
    		cout<<m<<endl;
    	}
     
    	return 0;
    }

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

int main(){
  long long n,k,ans=-1000000000;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<bits/stdc++.h>
using namespace std;

long long int sum,k,n,num[200000],to;

int main(){

    while(1){

    long long int ans=-100000000000;
    cin >> n >> k;
    if(n==0&&k==0)break;

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

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

    for(int i=k;i<n;i++){
        if(ans<sum)ans=sum;
        sum-=num[to++];
        sum+=num[i];
    }

    cout << ans << endl;

    sum=0;
    ans=0;

    }


return 0;
}

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

using namespace std;

int n,m,cnt;
int ans,an;
int a[100000];

int main(void){

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

    ans = 0;

    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( ans , an );
    }

    cout << ans << endl;

  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <numeric>
using namespace std;
int main(){
  int n, k;
  int N[100001], ans, sum;
  while(cin >> n >> k, n && k){
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }
    for(int i = 0 ; i < n - k ; i++){
      sum = 0;
      sum = accumulate(N+i, N+i+k, 0);

      /*for(int j = i ; j < k + i ; j++){
	sum += N[j];
	}*/
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(i=s=0;i<n;s+=a[i++],k<i&&(s-=a[i-k-1]),M<s&&(M=s))std::cin>>a[i];}