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>
using namespace std;

int main() {
    int n,k,i,ans=0;
    cin >> n >> k;
    while(n!=0 || k!=0){
        int a,sum[1000000],S;
        sum[0]=0;
    
        for(i=0;i<n;++i){
            cin >> a;
            sum[i+1] = sum[i] + a;
        }
    
        for(i=0;i<n-k;++i){
            S=sum[i+k]-sum[i];
            ans = max(ans,S);
        }
    
        cout << ans << endl;
        cin >> n >> k;
    }
}

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

using lint = long long;

int main(){
    int n, k;
    while(cin >> n >> k, n){
        vector<lint> sum(n + 1);
        for(int i = 1 ; i <= n ; ++i){
            cin >> sum[i];
            sum[i] += sum[i - 1];
        }

        lint ans = -(1LL << 62);
        for(int i = k ; i <= n ; ++i){
            ans = max(ans, sum[i] - sum[i - k]);
        }

        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#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(){
	long long n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		vector<long long> sum;
		long long num[n];
		rep(i,n)cin>>num[i];
		rep(i,n-k+1){
			long long alt=0;
			loop(j,i,i+k/2+1){
				alt+=num[j];
				if(j!=(i+k-1-j))alt+=num[i+k-1-j];
			}
			sum.push_back(alt);
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

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

const int MAX = 100005;
long long cum_sum[MAX];

int main() {
  // input
  while (true) {
    int n, k, tmp;
    cin >> n >> k;
    if (n == 0 && k == 0) break;
    for (int i = 1; i <= n; i++) {
      cin >> tmp;
      cum_sum[i] = cum_sum[i-1] + tmp;
    }

    long long ans {-MAX * n};
    for (int i = 1; i <= n-k; i++) {
      long long tmp_ans = cum_sum[i + k] - cum_sum[i];
      if (ans < tmp_ans) ans = tmp_ans;
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, k;
    while(cin >> n >> k, n|k){
        vector<ll> v(n+1, 0);
        for (int i = 0; i < n; ++i) {
            scanf("%lld", &v[i+1]);
        }
        partial_sum(v.begin(), v.end(), v.begin());
        ll ans = -INF<ll>;
        for (int i = 0; i < n-k+1; ++i) {
            ans = max(ans, v[i+k]-v[i]);
        }
        cout << ans << "\n";
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
long long n, k, a[200000], s, ret;
int main() {
	while (true) {
		cin >> n >> k; if (n == 0)break; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (i <= k)s += a[i]; }
		ret = s; for (int i = k + 1; i <= n; i++) { s -= a[i - k]; s += a[i]; ret = max(ret, s); }
		cout << ret << endl;
	}
	return 0;
}

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


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

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,ans = 0,sum = 0;
  cin >> n >> k;
  vary(ll,v,n,0);
  vary(ll,imos,n+1,0);
  rep(i,n){
    cin >> v[i];
    sum += v[i];
    imos[i] += sum;
  }
  ans = -inf;
  REP(i,k,n){
    ans = max(ans,imos[i]-imos[i-k]);
  }
  cout << ans << endl;
  return 0;
}

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

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

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

int main() {
    while (true) {
        int n, k;
        cin >> n >> k;
        if ((n | k) == 0) {
            break;
        }
        int* a = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int* s = new int [n - k + 1];
        s[0] = 0;
        for (int i = 0; i < k; i++) {
            s[0] += a[i];
        }
        int maxS = s[0];
        for (int i = 1; i <= n - k; i++) {
            s[i] = s[i - 1] - a[i - 1] + a[i + k - 1];
            if (maxS < s[i]) {
                maxS = s[i];
            }
        }
        cout << maxS << endl;
        delete[] a;
        delete[] s;
    }
}