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++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    vector<ll> ans;
    while (true){
        int n,k;cin>>n>>k;
        if (n==0 && k==0){
            break;
        }
        vector<ll> a(n);
        rep(i,0,n) cin>>a[i];
        vector<ll> b(n+1,0);
        rep(i,0,n) b[i+1] = b[i] + a[i];
        ll num = 0;
        rep(i,0,n-k){
            num = max(num,b[i+k]-b[i]);
        }
        ans.push_back(num);
    }
    for(auto x:ans){
        cout<<x<<endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int a[100000];
int main(){
	int n,k,best;
	while(true){
	cin>>n>>k;
	if(n==0&&k==0)
		break;
	best=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<k;i++)
		best+=a[i];
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k])
			best=best+a[i]-a[i-k];
	}
	cout<<best<<endl;
	}
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int inp[1000000];
	
int main() {
	int n,m;
	while(n=in(),m=in()){
		int i;
		for(i=0;i<n;i++){
			inp[i]=in();
		}
		Int max;
		Int sum=0;
		int k;
		for(k=0;k<m;k++){
			sum+=inp[k];
		}
		max=sum;
		for(i=0;i<=n-m;i++){
			if(max<sum)max=sum;
			sum-=inp[i];
			sum+=inp[i+m];
		}
		cout<<max;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(void){
	int n=0, k=0;
	int *a;
	long sum  = 0;
	long msum = 0;

	scanf("%d %d", &n, &k);
	a = (int*)malloc(sizeof(int) * n);
	for(int i=0; i<n; ++i){
		scanf("%d", a+i);
	}

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

	for(int i=0; k<n; ++i,++k){
		sum = sum - a[i] + a[k];
		if(sum > msum){
			msum = sum;
		}
	}
	printf("%d\n", msum);
	getchar();getchar();
	free(a);
	return 0;
}

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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) elems.push_back(item);
      item.clear();
    }
    else item += ch;
  }
  if (!item.empty()) elems.push_back(item);
  return elems;
}

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

signed main()
{
  int n, m;

  while (cin >> n >> m, n + m){
    int a[n], maxsum = 0;

    rep(i, n) a[i] = in();
    reps(i, 2, n) maxsum = max(maxsum, a[i - 2] + a[i - 1] + a[i]);
    print(maxsum);
  }

  return (0);
}

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

int main(){

    while(1){
        int n, k; cin >> n >> k;
        if(n == 0) break;

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

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

        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int n=0, k=0;
double a[100001] = {}, b[100001] = {}, ans=0;
int main(){
	while (true){
		
		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;
		}
		else{
			cout << ans << endl;
		}
	}
	return 0;
}

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

int main(void){
  int n , k;
  while(cin>>n>>k,n+k){
  vector<int> in(n,0);
  vector<int> dp(n,0);
  for(int i = 0 ; i < in.size() ; i ++) 
    cin>>in[i];
  int res = 0;
  for(int i = 0 ; i < in.size() - k ; i ++){
    for(int j = i ; j < i + k ; j ++){
      dp[i] += in[j]; 
    }
    res = max(res,dp[i]);
  }
  
  cout<<res<<endl;
  }
}

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

using namespace std;

int main()
{
	int n, k, s, b;
	while (1)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		int m[100001] = { 0 };
		int a[100001];
		for (int i = 0;i < n;i++)
			cin >> a[i];

		m[0] = 0;
		for (int i = 0;i < n;i++)
			m[i + 1] = m[i] + a[i];

		s = 0;
		for (int i = 1;i +k<=n;i++)
		{
			b = m[i + k ] - m[i ];
			if (s < b) 
				s = b;
		}

	}
	cout << s << endl;
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[])
{
  int n, k;
  cin >> n >> k;
  do {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    // 累積和を計算
    vector<int> com_sums(n + 1, 0);
    for (int i = 0; i < a.size(); i++) {
      com_sums[i + 1] = com_sums[i] + a[i];
    }

    int result = com_sums[k] - com_sums[k - k];
    for (int i = k + 1; i < a.size(); i++) {
      result = max(result ,com_sums[i] - com_sums[i - k]);
    }
    cout << result << "\n";

    cin >> n >> k;
  } while(n != 0);

  return 0;
}

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;
}}