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<bits/stdc++.h>
using namespace std;
int main(){
    int k,n,a[100]={0};
    double cube=0,ans=0;
    while(1){
       cin >> n >> k;
       if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n-k;i++){
       cube=0;
       for(int j=0;j<k;j++){
        cube +=a[i+j];
       }
       if(cube>ans)ans=cube;
    }
    cout << ans << endl;
    }
return 0;
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i,j;std::cin>>n>>k,n;printf("%d\n",s)){for(i=M=0;i<n;i++)std::cin>>a[i];for(i=n;i-->k;M<s&(M=s))for(j=s=0;j<k;j++)s+=a[i-j];}}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,k;
ll a[200000];

bool input(){
    scanf("%lld%lld",&n,&k);
    if(n == 0 && k == 0)
        return false;
    REP(i,n)
        scanf("%lld",a + i);
    return true;
}
void solve(){
    ll sum = 0;
    REP(i,k){
        sum += a[i];
    }
    ll maxi = sum;
    REP(i,n - k){
        sum = sum - a[i] + a[i + k];
        maxi = max(maxi,sum);
    }
    printf("%lld\n",maxi);
}
int main(){
    while(input())
    solve();
}

C++: #include <stdio.h>
int main(){
	for(;;){
		int max=0,set[100000],n,m,a,b,c;
		scanf("%d%d",&n,&m);
		if(n==0&&m==0){
			break;
		}
		for(a=0;a<n;a++){
			scanf("%d",&set[a]);
		}
		for(a=0;a<n-m;a++){
			c=0;
			for(b=0;b<m;b++){
				c+=set[a+b];
			}
			if(max<c)max=c;
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#define ini 0
using namespace std;


int rlay[100001];

int main (){

while (1){
memset(rlay, 0,sizeof(rlay));

int n,k,input,ansmax=0;
cin>>n>>k;
if (n==0&&k==0)break;

rlay[0]=ini;
for (int i=1;i<=n;i++){
        cin>>input;
        rlay[i]=input+rlay[i-1];
}

for (int i=n;i-k>0;i--){
        ansmax = max ( rlay[i]-rlay[i-k] ,ansmax );
}

cout<<ansmax<<endl;

}
return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		cin>>a>>b;
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>e[c];
		}
		for (int f=0;f<=a-b;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
			if (e[f]>=max) max=e[f];
		}
		cout<<max<<endl;
	}
	return 0;
}

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

int main()
{
    int i, n, k, temp;
    cin >> n >> k;
    int a[n];
    for(i=0; i<n ;i++){
        cin >> a[i];
    }
    for(i=0; i<2; i++){cin >> temp;}
    int max_val;
    int S;
    //--init--
    S = 0;
    for(i=0; i<k; i++){
        S += a[i];
    }
    max_val = S;
    for(i=0; i<n-k; i++){
        S += a[i+k];
        S -= a[i];
        if(max_val < S){
            max_val = S;
        }
    }
    std::cout << max_val << std::endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, k;
ll bit[111111];
ll a;

ll sum(int i)
{
  ll s = 0LL;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, ll d)
{
  while(i <= n){
    bit[i] += d;
    i += i & -i;
  }
}

int main()
{
  while(cin >> n >> k, n){
    rep(i, 111111) bit[i] = 0LL;

    rep(i, n){
      cin >> a;
      add(i + 1, a);
    }

    ll res = sum(k);
    erep(i, k + 1, n) maxup(res, sum(i) - sum(i - k));
    cout << res << endl;
  }

  return 0;
}

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

using namespace std;

int n,m,cnt;
int ans,an;
int a[100000];

int main(void){

  while( cin >> n >> m , n || m ){

    ans = 0;

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

    for( int i = 0 ; i <= n - m ; i++ ){
      an = 0;
      cnt = 3;
      for( int j = i ; j < i + 3 ; j++ ){
	an += a[j];
      }
      ans = max( ans , an );
    }

    cout << ans << endl;

  }
  return 0;
}

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

int main()
{
	while (1)
	{
		int n, k;
		std::cin >> n >> k;

		if (n == 0 && k == 0)
			break;

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

		int s = 0;
		for (int i = 0; i != k; ++i)
			s += vec[i];

		int m = std::numeric_limits<int>::min();
		m = std::max(s, m);
		for (int i = 0; i != n - k; ++i)
		{
			s -= vec[i];
			s += vec[i + k];
			m = std::max(s, m);
		}

		std::cout << m << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long n, k;
	while (cin >> n >> k&&n != 0 && k != 0) {
		long long  a[100000], sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (i < k) sum += a[i];
		}
		long long 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 <queue>
using namespace std;
int main(){
	queue<int> a;
	while(1){
		int n,k,num,max,tmp;
		cin >> n >> k;
		if(!n&&!k) break;
		max=tmp=0;
		for(int i=0;i<k;i++){
			cin >> num;
			a.push(num);
			max+=num;
		}
		n-=k;
		tmp=max;
		while(n--){
			cin >> num;
			a.push(num);
			tmp+=a.back()-a.front();
			a.pop();
			if(max<tmp) max = tmp;
		}
		cout << max << endl;
		return 0;
	}
}

C++: #include <iostream>
#include <algorithm>
#define N 5000
using namespace std;
int main(){
  int n,k,data[N],maxv,sum,i,j;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    for(i=0;i<n;i++) cin >> data[i];
    maxv=-2000000000;
    for(i=0;i<n;i++){
      sum=0;
      if(i<=n-k){
	for(j=i;j<i+k;j++){
	  sum+=data[j];
	}
	maxv=max(maxv,sum);
      }
    }
    cout << maxv << endl;
  }
}

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

using namespace std;

void solve()
{
	int m, n;
	while(cin >> m >> n)
	{
		if(!m && !n)
		{
			break;
		}
		vector<int> Vec(m);
		for(int i = 0; i < m; ++i)
		{
			cin >> Vec[i];
		}
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			sum += Vec[i];
		}
		int max = sum;
		for(int i = 1; i < m - n + 1; ++i)
		{
			sum += Vec[i + n - 1] - Vec[i - 1];
			if(sum > max)
			{
				max = sum;
			}
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}