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 <cstring>
#include <climits>

#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

static const int DAT_SIZE = 1<<18;
typedef long long ll;

ll data[DAT_SIZE], datb[DAT_SIZE];

void add(ll a, ll  b, ll x, ll  k, ll  l, ll  r){
    
    if(a <= l && r <= b){
        data[k] += x;
    }
    else if(l < b && a < r){
        datb[k] += (min(b, r) - max(a, l)) * x;
        add(a, b, x, k*2+1, l, (l+r)/2);
        add(a, b, x, k*2+2, (l+r)/2, r);
    }
}

ll sum(ll  a, ll  b, ll  k, ll  l, ll  r){
    
    if(b <= l || r <= a){
        return 0;
    }
    else if(a <= l && r <= b){
        return data[k] * (r-l) + datb[k];
    }
    else{
        ll res = (min(b, r) - max(a, l)) * data[k];
        res += sum(a, b, k*2+1, l, (l+r)/2);
        res += sum(a, b, k*2+2, (l+r)/2, r);
        return res;
    }
}

int main(){
    
	int n, k;
	
	while(cin >> n >> k, (n||k)){
    	
		CLR(data);
		CLR(datb);

	    for(int i=0; i<n; ++i){
			int a;
			scanf("%d", &a);
  			add(i, i+1, a, 0, 0, n);
		}
    
		ll ma = LLONG_MIN;

		for(int i=0; i<n-k; ++i){ 
			ma = max(ma, sum(i, i+k, 0, 0, n));
   	 	}
   	 
		cout << ma << endl;
	}

    return 0;
}

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

int main(void)
{
	int n,m,a;

	
	while(cin >> n >> m, n | m){
		int d[100001] = {};
		cin >> d[0];
	
		for(int i = 1; i < n; i++){
			cin >> a;
			d[i] += d[i-1] + a;
		}
		int MAX = 0;
		for(int i = 0; i < n - m; i++){
			if(d[i+m] - d[i] > MAX)
				MAX = d[i+m] - d[i];
		}
		cout << MAX << endl;
	}

	return 0;
}

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

int main(){
    int n,a[100001]={0},k,sum,p;
int i,j,h;
while(1){
cin>>n>>k;
if(n==0&&k==0)break;
cin>>a[1];
for(i=2;i<=n;i++){
	cin>>a[i];
	a[i]+=a[i-1];
}
sum=a[k];
for(i=k+1;i<=n;i++){
    sum=max(sum,a[i]-a[i-k]);
	}
cout<<sum<<endl;
}
return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

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

C++: #include <iostream>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int *a, *a2, m, n, t1;
	
	while(1){
		cin >> n >> m;
		if(n == 0){
			break;
		}
		
		a = (int *)calloc(n-m+1, sizeof(int));
		a2 = (int *)calloc(n, sizeof(int));
		
		for(int i = 0; i < n; i++){
			cin >> t1;
			a2[i] = t1;
		}
		
		for(int i = 0; i < m; i++){
			a[0] += a2[i];
		}
		
		for(int i = 0; i < n-m; i++){
			a[i+1] += (a2[m+i] + a[i] - a2[i]);
		}
		
		sort(a, a+(n-m+1));
		cout << a[n-m] << endl;
		
		free(a2);
		free(a);
	}
	
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  
  int n,k,max=0,ans,i;
  cin >> n >> k;
  int a[n];
  
  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
    
    if(i < k){
      max += a[i];
      ans = max;
    }
    else {
      max = max + (a[i] - a[i-k]);
      if(ans < max) ans = max;
    }
  }

  printf("%d\n",ans);
  return (0);
}

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

int n = 0;
int k = 0;
int a[100020] = {0};
int table[100020] = {0};

bool input() {
  cin >> n >> k;
  if (!n && !k) return false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    table[i+1] = a[i] + table[i];
  }
  return true;
}

int solve() {
  int Max = -1001001001;
  for (int i = 0; i < n-k; i++) {
    Max = max(Max, table[i+k]-table[i]);
  }
  return Max;
}

int main() {
  while(input()) {
    printf("%d\n", solve());
  }
  return 0;
}

C++: //include----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n, m, k;
VI a, b, c;
#define mod 1000000007
//function-------------------------------------------------------------------------------------------------------------------- 
int main() {
	while ( true ) {
		scanf( "%d %d", &n, &m );
		if ( !n && !m ) {
			return 0;
		}
		int e = 0;
		rep( i, n ) {
			scanf( "%d", &k );
			a.push_back( k );
			e = max( e, k );
		}
		int mx = 0;
		rep( i, n - m + 1 ) {
			int d = 0;
			rep( j, m ) {
				d += a[ i + j ];
				if ( mx >= d + e * ( m - j - 1 ) ) {
					break;
				}
			}
			mx = max( mx, d );
		}
		printf( "%d\n", mx );
		a = VI();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    for(int count = 0;  count < 5; count++){
        vector<int> none(2);
        int N, k;
        cin >> N >> k;
        vector<int> a(N);
        for(int i = 0; i < N; i++){
		cin >> a.at(i);
            
        }
        int ans = 0;
        int total = 0;
        for(int i = 0; i < N; i++){
            if(i < k) total += a[i];
		else total = total + a[i] - a[i-k];
		if(ans < total) ans = total;
            
        }
        cout << ans << endl;
        for(int i = 0; i < 2; i++){
            cin >> none.at(i);
            
        }
　　}
}