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 <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int a[200000];

int main(){
	int n, k;
	while(true){
		cin >> n >> k;
		if(n == 0 && k == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		long long int max;
		long long int sum;
		
		sum = 0;
		
		for(int i = 0; i < k; i++){
			sum += a[i];
		}
		
		max = sum;
		
		for(int i = k; i < n; i++){
			sum += a[i];
			sum -= a[i - k];
			if(max < sum){
				max = sum;
			}
		}
		
		printf("%lld\n", max);
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#define INF 1000000000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int a[100000];
int main(){
	int n, k;
	while (scanf("%d%d", &n, &k), n){
		rep(i, n)
			scanf("%d", &a[i]);
		int Max = -INF;
		rep(i, n - k + 1){
			int sum = 0;
			rep(j, k){
				sum += a[i + j];
			}
			Max = max(Max, sum);
		}
		printf("%d\n", Max);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n,k;
  int a[100001];
  cin>>n>>k;
  REP(i,n)cin>>a[i];
  int sum = 0;
  int mx;
  REP(i,k){
    sum+=a[i];
  }
  mx = sum;
  for(int i=k;i<n;i++){
    sum-=a[i-k];
    sum+=a[i];
    mx = max(sum,mx);
  }
  cout<<mx<<endl;
  return 0;
}

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

int main(){
  long long n,k;

  while(1) {
    long long ans=-1000000000;
    cin>>n>>k;
    if(n == 0 and k == 0) break;
    long long a[n];for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<n-k+1;i++){
      long long temp=0;
      for(int j=i;j<i+k;j++){
        temp+=a[j];
      }
      ans=max(temp,ans);
    }
    cout<<ans<<endl;
  }
}

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

vector<int> ret;

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

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

int main() {
    do {
        int n, k;
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        vector<int> 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 <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;while (1) {scanf("%d %d",&N,&K);if (!N) return 0;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];ans=j;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 main()
{
  int n,k;
  cin >> n >> k;
while(n!=0||k!=0){
  int l, i=0, a[100000], S[100000];
  S[0] = 0;
  while(cin >> l){
    a[i] = l;
    if (i>=1)S[i] = S[i-1]+a[i-1];
    i++;
  }
  int q = i; i = 0;int m = a[0];
  while(k+i<=q){
    if (m > S[i+k-1]-S[i])
    m = S[i+k-1]-S[i];
    i++;
  }
  cout << m << endl;
}
cin >> n >> k;
}

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];
			if(i!=n-m)sum+=inp[i+m];
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n, k, a[100000];

int main() {
  while (1) {
    scanf("%lld%lld", &n, &k);
    if (n == 0) break;
    for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
    ll sum = 0;
    for (ll i = 0; i < k; i++) sum += a[i];
    ll ans = sum;
    for (ll i = k; i < n; i++) {
      sum += a[i];
      sum -= a[i - k];
      ans = max(ans, sum);
    }
    printf("%lld\n", ans);
  }
}

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

using namespace std;

int n, k ,i = 0;
long long int a[100000];
long long int result[100][2];

int main()
{
	for (;; i++)
	{
		cin >> n >> k;
		if (n == 0)
		{
			break;
		}

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

		for (int p = 0; p < n - k; p++)
		{
			for (int q = 0; q < k; q++)
			{
				result[i][0] += a[p + q];
			}
			result[i][1] = max(result[i][0], result[i][1]);
			result[i][0] = 0;
		}
	}
	for (int p = 0; p < i; p++)
	{
		cout << result[i][1] << endl;
	}

	getchar();
	getchar();

	return 0;
}

C++: const int MAX_N = 1 << 17, INF = 1 << 24;
class BIT{
public:
	BIT(int _n)
		:n(_n){
		std::fill(bit, bit+n, 0);
	}
	int sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	int add(int i, int x){
		while(i <= n){
			bit[i] += x;
			i += i & -i;
		}
	}
private:
	int bit[MAX_N], n;
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		BIT b(n+1);
		for(int i=1;i<=n;i++){
			int a_i;
			std::cin >> a_i;
			b.add(i, a_i);
		}

		int res = -INF;
		for(int i=1;i+k-1<=n;i++){
			res = std::max(res, b.sum(i+k-1) - b.sum(i-1));
		}

		std::cout << res << std::endl;
	}
}

C++: #include <iostream>
#include <algorithm>
constexpr int MAX_N=100000;

int n,k;
int a[MAX_N];
long long int sum=0;
long long int res=0;

int main(){
    while(1){
        std::cin>>n>>k;
        if(n+k==0)
            break;
        res=0;
        sum=0;

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

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

        res=sum;

        int s=0,t=k;

        while(t<=n){
            sum-=a[s];
            sum+=a[t];
            ++s;
            ++t;
            res=std::max(res,sum);
        }
        std::cout<<res<<std::endl;
    }
    return 0;
}

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

int main(){
  int n,k;
  int a[1000000];

  for(;;){
    cin >> n >> k;
    if(!n && !k)break;

    for(int i=0;i<n;i++)cin >> a[i];
    int sum = 0;
    for(int i=0;i<k;i++)sum += a[i];
    int m = sum;
    for(int i=k;i<n;i++){
      sum += a[i] - a[i-k];
      m = max(m,sum);
    }
    cout << m << endl;
  }
}