Go: package main

import "fmt"

func main() {

	for true {
		var n, k int
		fmt.Scan(&n, &k)

		if n == 0 && k == 0 {
			return
		}
		
		a := make([]int, n)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if i == 0 {
				ans[i] = a[i]
			} else {
				ans[i] = ans[i-1] + a[i]
			}
		}
		max := 0
		for i := k; i < n; i++ {
			t := ans[i] - ans[i-k]
			if max < t {
				max = t
			}
		}
		fmt.Println(max)
	}
}

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

int main(){
  int numn,lisn,num;
  vector<int> outp;
  int outn = 1;
  for(int l = 0;;l++){
    cin >> numn >> lisn;
    if(numn == 0 && lisn == 0){
      break;
    }
    outp.resize(l+1,0);
    vector<int> lists(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num;
      lists[n] = num;
    }
    for(int k = 0;k<numn-lisn+1;k++){
      outn = lists[k] + lists[k + 1] + lists[k + 2];
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << endl;
  }
}

C++: #include <iostream>

using namespace std;

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

  if ((k == 0 && n == 0)) {
    return 0;
  }
  while (1) {
    int a[100000];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t > s) {
        s = t;
      }
    }
    cout << s << endl;
    cin >> n >> k;

    if ((k == 0 && n == 0)) {
      return 0;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const long long INF = 999999999999;

vector<ll> ret;

void solve(vector<ll>& a, ll k) {
    ll n = a.size();
    vector<ll> cs(n+1, 0);
    for(int i = 1; i < n+1; i++) {
        cs[i] = cs[i-1];
        cs[i] += a[i-1];
    }

    ll ans = (-1) * INF;
    for(int i = 0; i < n+1; i++) {
        ll now = cs[i+k] - cs[i];
        ans = max(ans, now);
    }
    ret.push_back(ans);
}

int main() {
    do {
        ll n, k;
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        vector<ll> a(n, 0);
        for(int i = 0; i < n; i++) cin >> a[i];
        solve(a, k);
    } while(true);

    for(auto &r : ret) {
        cout << r << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main(){
  int n, k;
  int N[100001], ans, sum;
  while(cin >> n >> k, n && k){
    memset(N, 10001, sizeof(N));
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }
    for(int i = 0 ; i < n - k ; i++){
      sum = 0;
      for(int j = i ; j < k + i ; j++){
	sum += N[j];
	//if(N[j+k-1] > 10000) break;
      }
      ans = max(ans, sum);
      //cout << ans << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int n, k, a[100000] = {};
	long long int sum = -10000000, tmp;
	while(cin >> n >> k){
		if(n == 0 && k == 0) break;
		for(int i = 0;i<n;i++){
			cin >> a[i];
			if(i < k) tmp += a[i];
		}
		for(int i = 0;i + k<n;i++){
			if(sum < tmp) sum = tmp;
			tmp = tmp - a[i] + a[i+k];
		}
		cout << sum << endl;
	}
	return 0;
}

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

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

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

  int a[101010] = {0};

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

  int max_n = -1e9;
  for (int i = 0; i < n - k; i++){
    max_n = max(max_n, a[k + i] - a[i]);
  }

  cout << max_n << endl;
}
#include <bits/stdc++.h>
using namespace std;

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

  int a[101010] = {0};

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

  int max_n = -1e9;
  for (int i = 0; i < n - k; i++){
    max_n = max(max_n, a[k + i] - a[i]);
  }

  cout << max_n << endl;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
int a[MAXN], sum[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    	cin >> a[i];
    for (int i = 0; i < N; i++) 
    	sum[i+1] = sum[i]+a[i];
    int ans = -1e9-1;
    for (int i = 0; i+K <= N; i++) {
    	ans = max(ans, sum[i+K]-sum[i]);
    }
    cout << ans << endl;
    return 0;
}

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

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

		int ans = 0, sum = 0;
		for(int i = 0; i < k - 1; ++i)
			sum += a[i];

		for(int i = k - 1; i < n; ++i) {
			sum += a[i];
			chmax(ans, sum);
			sum -= a[i - k + 1];
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

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



int main(){
        int n, k;
        vector<double> v;
        cin >> n>>k;

        int num=0;
        for(int i=0; i<=n; i++) {  //ベクターに格納
                cin>>num; //入力をnumに代入
                v.push_back(num); //ベクターvにプッシュ
        }


        int max=0;
        int 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;
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j;while (1) {scanf("%d %d",&N,&K);if (!N || N==EOF) return 0;ans=-1000000007,j=0;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);}}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa, bool isBegin)
{
	int temp = 0;
	int i;
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa, 0);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0, 1));
	}
}

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

using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (!n && !k) return 0;
    int a[n];
    long long result = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        result += a[i];
    }
    for (int i = k; i < n; i++)
      result = max(result, result - a[i-k] + a[i]);
    cout << result << endl;
  }
}