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;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main(){
  int n,k;
  while(cin >> n >> k,n){
    vector<int> vec(n);
    REP(i,n) cin >> vec[i];
    int ans = 0;
    REP(i,k) ans += vec[i];
    int tmp = ans;
    FOR(i,k,n){
      tmp += vec[i];
      tmp -= vec[i-k];
      ans = max(ans,tmp);
    }
    cout << ans << endl;
  }
}

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

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

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

using namespace std;

int main() {
    while(true) {
        int a, b;
        cin >> a >> b;
        if(!a && !b) break;

        vector<vector<int> > dp(a, vector<int>(b, 0));
        dp[0][0] = 1;

        int n;
        cin >> n;
        while(n--) {
            int x, y;
            cin >> x >> y;
            --x; --y;
            dp[x][y] = -1;
        }
        for(int i = 0; i < a; ++i) {
            for(int j = 0; j < b; ++j) {
                if(dp[i][j] == -1) continue;
                if(i-1 >= 0 && dp[i-1][j] != -1) dp[i][j] += dp[i-1][j];
                if(j-1 >= 0 && dp[i][j-1] != -1) dp[i][j] += dp[i][j-1];
                if(i+1 < a && dp[i+1][j] != -1) dp[i][j] += dp[i+1][j];
                if(j+1 < b && dp[i][j+1] != -1) dp[i][j] += dp[i][j+1];
            }
        }

        cout << dp[a-1][b-1] << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
long su[100000010] = { 0 };
long sai;
int main()
{
	long n, k;
	long i, j;
	long a;
	while (cin >> n >> k, n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{
			cin >> a;
			su[i] = su[i - 1] + a;
		}
		sai = 0;
		for (i = k; i <= n; i++)
		{
			if (sai < su[i] - su[i - k])
			{
				sai = su[i] - su[i - k];
			}
		}
		cout << sai << endl;
	}
	return 0;
}

C++: #include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		scanf("%d %d",&a,&b);
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			scanf("%d",&d);
			e[c]=d;
		}
		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];
		}
		printf("%d\n",max);
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

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

C++: #include<iostream>
using namespace std;
main(){
  int n,k,a;
  int node1=0,node2,max;
  int ruiseki[100001]={0};
  cin>>n>>k;
  node2=k;
  for(int i=1;i<=n;i++){
    cin>>a;
    ruiseki[i]=ruiseki[i-1]+a;
    if(i>=k){
      if(i==k){
	max=ruiseki[node2]-ruiseki[node1];
      }
      else if(max<ruiseki[node2]-ruiseki[node1]){
	max=ruiseki[node2]-ruiseki[node1];
      }
      node1++;
      node2++;
    }
  }
  cout<<max<<endl;
}

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

int main(){
  int n,k,a,s,m;
  while(cin>>n>>k,n||k){
    a=0;
    queue<int> q;
    n-=k;
    while(k--){
      cin>>s;
      a+=s;q.push(s);
    }
    m=a;
    while(n--){
      cin>>s;
      q.push(s);
      a=a+s-q.front();
      q.pop();
      m=max(m,a);
    }
    cout<<m<<endl;
  }
  return 0;
}

C++: #include <cstdio>

int main() {
    long n, k;
    for (;;) {
        long a[100002] = {};
        scanf("%ld %ld", &n, &k);
        if (n == 0)
            return 0;
        for (long i = 0; i < n; i++) {
            scanf(" %ld", &a[i]);
        }
        long max = -2147483648;
        for (long i = 0; i < n - k; i++) {
            long result = 0;
            for (long l=i; l<i+k; l++)
                result += a[l];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=-100000000,sum;
	cin>>n>>k;
	while(n!=0){
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
	cin>>n>>k;
	}
return 0;
}

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

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long


using namespace std;


int array[200000];

int main (void){
	//printf("%lld:::%lld",(LL)INF,(LL)LLINF);

	int n;
	int k;

	LL sum;
	LL maxNum;

	while(true){
		sum = 0;
		maxNum = -1*(LL)LLINF;
		scanf("%d",&n);
		scanf("%d",&k);
		if((n==0)||(k==0))break;
		for(int i=0;i<n;i++){
			scanf("%d",array+i);
		}
		for(int i=0;i<k;i++){
			sum += array[i];
		}
		maxNum = max(maxNum,sum);
		for(int i=0;i<n-1-k;i++){
			maxNum = max(maxNum,sum = (sum-array[i]+array[k]));
		}
		printf("%lld",maxNum);
	}

	return 0;
}

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

using namespace std;

long long int a[1000000];

int main(){
	
	int n, k;
	
	while(true){
	
	cin >> n >> k;
		if(n == 0){
			break;
		}
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	long long int max = -1000000000000000;
	
	long long int cur = 0;
	
	for(int i = 0; i < k; i++){
		cur += a[i];
	}
	
	for(int i = k; i < n; i++){
		if(max < cur){
			max = cur;
		}
		cur += a[i] - a[i - k];
		if(max < cur){
			max = cur;
		}
	}
	
	cout << max << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
  int n,k;
  cin>>n>>k;
  int a[100100];
  REP(i,n)cin>>a[i];
  int sum=0,ans=0;
  REP(i,n){
    if(i<k){
      sum+=a[i];
    }else{
      sum-=a[i-k];
      sum+=a[i];
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}

C++: #include <cstdio>

using namespace std;

typedef long long ll;

ll max1(ll a, ll b) { return a > b ? a : b; }

int main()
{
	ll n, k; scanf("%lld %lld", &n, &k);

	ll N[100001];

	for (ll i = 1; i <= n; ++i) scanf("%lld", &N[i]);

	ll sum = 0;

	for (ll i = 1; i <= k; ++i) sum += N[i];

	for (ll i = k; i < n; ++i) sum = max1(sum, sum - N[i-k+1] + N[i+1]);

	printf("%lld\n", sum);
}