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<vector>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    vector<int>in(a);
    rep(i,a)cin>>in[i];
    int sum=0;
    rep(i,b)sum+=in[i];
    int ma=sum;
    rep(i,a-b){
      sum-=in[i];
      sum+=in[i+b];
      ma=max(ma,sum);
    }
    cout<<ma<<endl;
  }

}

C++: #include<iostream>

using namespace std;

#define MAX 100000
#define INF (10000*100000+1)
int main(){

	int n,k,a[MAX];
	long long num,max;

	while(1){

		cin>>n>>k;
		if(n==0&&k==0) break;

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

		max=-1*INF;
		for(int i=0;i<=n-k;i++){
			num=0;
			for(int j=0;j<k;j++){
				num+=a[i+j];
			}
			max=(max<num)?num:max;
		}
		cout<<max<<endl;
		
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, k;
ll a[100010], s[100010];
vector<ll> v;

int main() {
    while (cin >> n >> k) {
        if (n == 0) break;
        rep(i, n) cin >> a[i];
        rep(i, n) s[i+1] = s[i] + a[i];

        ll ans = 0;
        for (int i = 0; i + k - 1 < n; i++) {
            ll tmp = s[i+k] - s[i];
            chmax(ans, tmp);
        }
        v.push_back(ans);
    }
    for (ll &x: v) cout << x << endl;
}

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

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

using namespace std;

int N, K;
vector<int> DpSum;

int solve() {
	int sum;

	sum = -1000000001;
	for (int i = 1; i + K <= N; ++i) {
		sum = max(sum, DpSum[i + K] - DpSum[i]);
	}

	return sum;
}

int main() {
	int a;

	while (cin >> N >> K, N) {
		DpSum.clear();
		DpSum.resize(N + 1);
		DpSum[0] = 0;
		for (int i = 1; i <= N; ++i) {
			cin >> a;
			DpSum[i] += DpSum[i - 1] + a;
		}
		cout << solve() << endl;
	}

	return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, k;
ll a[111111];

int main()
{
  while(cin >> n >> k, n){
    rep(i, n) cin >> a[i];

    rep(i, n - 1) a[i + 1] += a[i];

    ll res = a[k - 1];
    rrep(i, k, n) maxup(res, a[i] - a[i - k]);
    cout << res << endl;
  }

  return 0;
}

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

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


int main(){
    while (1){
	vector<int> inp;
	int n, k, input;
	cin >> n >> k;
	if (!(n || k)) break;

	for (int i = 0; i < n; i++){
	    cin >> input;
	    inp.push_back(input);
	}
	
	int right = inp.size(), left = 0, sum = 0;
	for (int i = 0; i < inp.size(); i++) sum += inp[i];
	
	while (right - left >= k){
	    if (inp[right] > inp[left]){
		sum -= inp[left];
		left++;
	    }
	    else {
		sum -= inp[right];
		right--;
	    }
	}
	cout << sum << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		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++){
			if (a[i + 2] == 0) break;
			b[i] = a[i] + a[i + 1] + a[i + 2];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<chrono>
#include<string>
#include<chrono>

using namespace std;






int main() {

	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	






	
	
	//system("pause");
	return 0;
}

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


int main(){
  int n, k;
  int a[100100];
  int b[100100];
  for(;;){
    cin >> n >> k;
    if(n==0 && k==0) break;
    
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    b[0] = 0;
    for(int i=0; i<n; i++){
      b[i+1] = b[i] + a[i];
    }
    int mx = -100000;
    for(int i=0; i<n-k+1; i++){
      int s = b[i+k] - b[i];
      if(mx < s) mx = s;
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k,x=0,ma=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-k;i++){
		x=0;
		for(int j=0;j<k;j++){
			x+=a[i+j];
		}
		ma=max(ma,x);
	}
	cout<<ma<<endl;
return 0;
}