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>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int gomi;
  cin >> gomi >> gomi;
  int ans = 0;
  for(int i = 0; i < k; i++) {
    ans += a[i];
  }
  int mx = ans;
  for(int i = 0; i < n - k; i++) {
    mx = mx + a[k + i] - a[i];
    ans = max(mx, ans);
  }

  cout << ans << endl;
  return 0;
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	while (cin >> n >> k&&n != 0 && k != 0) {
		int a[100000], sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (i < k) sum += a[i];
		}
		int s = 1, e = k, f;
		while (e < n) {
			f = sum;
			sum += a[e];
			sum -= a[s - 1];
			sum = max(sum, f);
			s++;
			e++;
		}
		cout << sum << endl;
	}
}

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

int main() {
	while(1){
		int n,k,b[100010]={},sum[100010]={};
		cin>>n>>k;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>b[i];
		}
		for(int i=0;i<(n-k+1);i++){
			for(int j=0;j<k;j++){
				sum[i]+=b[j+i];
			}
		}
		sort(sum,sum+(n-k+1), greater<int>()); 
		cout<<sum[0]<<endl;
	}
	return 0;
}

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 x = 0; x<k; x++){
			b[1] += a[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: // #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------


int main(){
  ll N,K;
  cin >> N >> K;
  while(1){
    if(N==0 && K==0){
      break;
    }
    vector<ll> a(N);
    for(int i=0; i<N; i++){
      cin >> a[i];
    }
    vector<ll> S(N+1,0);
    for(int i=1; i<N; i++){
      S[i+1] = S[i] + a[i];
    }
    ll ans=0;
    for(int i=K; i<=N; i++){
      chmax(ans, S[i]-S[i-K]);
    }
    cout << ans << endl;
    cin >> N >> K;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int INF = 1001001001;

int main(){
    while(true){
        int n, k; cin >> n >> k;
        if(n==0 && k==0) break;
        vector<int> a(n);
        rep(i,n) cin >> a[i];
        vector<int> sum(n+1,0);
        rep(i,n) sum[i+1] = sum[i] + a[i];
        int ans = -INF;
        for(int i = 0; i <= n-k; ++i){
            ans = max(ans, sum[i+k] - sum[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

C++: /**********************************************

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

last updated: 2013-07-10@16:16

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){
                
                int n=0;
                int k=0;
                int all=0;
                int total=0, answer=0;
                vector<int> data(5000);

                cin >> n >> k;
                //cout << "n=" << n << "k=" << k << endl;
                if(n==0 && k==0)break;
                
                for(int i=0; i<n; i++){
                        cin >> data[i];
                }
               

                for(int j=0; j<n-k; j++){
                        
                        for(int i=0; i<k; i++){
                                total = total + data[j+i];
                        }
                        if( answer < total){
                                answer = total;
                        }
                        total = 0;
                }

                cout << answer << endl;
                
        }

        return 0;

}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n, k, a[100010];
	while(cin >> n >> k)
	{
		if(n==0 && k==0) break;
		rep(i, n) cin >> a[i];
		int sum=0, ans;
		rep(i, k) sum+=a[i];
		ans=sum;
		rep(i, n-k)
		{
			sum+=(a[i+k]-a[i]);
			ans=max(sum, ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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



int main(){
        int n, k,max,temp,num;
        while(true) {  //ベクターに格納
                cin >> n>>k;
                if(n==k==0) break;
                vector<double> v;
                for(int i=0;i<n;i++){
                  cin>>num; //入力をnumに代入
                  v.push_back(num); //ベクターvにプッシュ
                }

                max=0;
                temp=0;
                for(int i=0; (i+k)<=n; i++) {
                        for(int j=0; j<k; j++) {
                                temp+=v[i+j]; //tempにvのiからi+k番目までの総和を代入
                        }
                        //cout<<temp<<endl;
                        if(temp>max) max=temp; //tempが最も大きい数値ならmaxを更新
                        temp=0; //tempの初帰化
                }
                cout<<max<<endl;
        }
}