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 n,k,i,ans=0;
    cin >> n >> k;
    while(n!=0 || k!=0){
        int a[n+1],sum[n+1],S[n+1];
        cin >> a[0];
        sum[0]=a[0];
    
        for(i=1;i<n;++i){
            cin >> a[i];
            sum[i] = sum[i-1] + a[i];//2n
        }
    
        for(i=0;i<n-k+1;++i){
        S[i]=S[i+k-1]-S[i];
        ans = min(ans,S[i]);
        }
    
        cout << ans << endl;
        cin >> n >> k;
    }
}

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

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

int max(int a, int b){
	if(a > b) return a;
	else return b;
}

int main(){
	const int MAX_N = 100000;
	int n, a[MAX_N], k, S, S1, S2;
	int p;
	
	while(true){
		scanf("%d%d", &n, &k);
		if(n == 0 && k == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		
		S = 0;
		for(p = 0; p < k; p++){
			S += a[p];
		}
		S1 = S;
		
		while(p < n){
			S2 = S1 + a[p] + a[p - k];
			
			S = max(S, S2);
			
			S1 = S2;
		}
		
		printf("%d\n", S);
	}
	
	return 0;
}

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

int main() {
  int n,k;
  while(cin>>n>>k, n|k) {
    vector<int> v(n);
    for(int i=0; i<n; ++i)
      cin>>v[i];

    int maxsum = 0,nsum = 0;
    for(int i=0; i<k; ++i) {
      maxsum += v[i];
      nsum += v[i];
    }
    for(int i=k; i<n; i++) {
      maxsum = max(nsum-v[i-k]+v[i], maxsum);
      nsum = nsum-v[i-k]+v[i];
    }

    cout<<maxsum<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
	while(true){
	int n , k ,ans;
	double a[100001] = {}, b[100001] = {};
	cin >> n >> k;
	if (n==0||k==0)	break;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n-k+1; i ++){
		b[i] = a[i] + a[i + 1] + a[i + 2];
		if (b[i]>b[i - 1]){
				ans = b[i];
		}
	}
	cout << ans << endl;
	}
	return 0;
}

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

const int MAX_N = 100009;

int n, k, a[MAX_N];

int s[MAX_N];

int main() {
    while (true) {
        s[0] = 0;

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

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

        int ans = -1000000007;
        for (int i = 0; i + k <= n; i++) {
            ans = max(ans, s[i+k] - s[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<stdio.h>
int ar[100000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,k;
	int i,j;
	int ans=0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)scanf("%d",&ar[i]);
	int res=0;
	for(i=0;i<k;i++)res+=ar[i];
	ans=max(ans,res);
	for(i=k;i<n;i++){
		res+=ar[i];
		res-=ar[i-k];
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa, bool isBegin)
{
	int temp = 0;
	int i;
	if(isBegin == 1){for(i = 0; i < k; i++){temp += suretu[cont+i];}}
	else{temp += wa + suretu[cont+k-1];}
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa, 0);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0, 1));
	}
}

C++: #include <iostream>

using namespace std;
int main()
{
    int i, k;
    cin >> i;
    cin >> k;
    int a[i], b[i];
    
    for(int j = 0 ; j < i ; j++)
        cin >> a[j];
    
    b[0] = a[0];
    for(int j = 0 ; j < i-1 ; j++)
        b[j+1] = b[j] + a[j+1];
    
    int N = b[k-1];
    for(int j = 0 ; j < i-k ; j++){
        if( b[j+k] - b[j] > N ){
            N = b[j+k] - b[j];
        }
    }
    
    cout << N <<endl;
}

C++: #include <iostream>
#include <vector>
 
using namespace std;
 
const int MAX = 100000;
vector<int> num(MAX);
 
int main() {
    int n, k;

    while (cin>>n>>k, n||k) {
      int sum = 0;
      int ans = 0;

      for (int i = 0; i < n; i++) {
        cin >> num[i];
        if (i < k) { 
          sum += num[i]; 
          ans = sum; 
        }
        else { 
          sum = sum + num[i] - num[i-k]; 
          ans = max(ans, sum); 
        }
      }
      cout << ans << endl;
    }
 
  return 0;
}

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

int a[100000];
int main() {
    const int INF = 1e9;
    int n, k;
    while(~scanf("%d%d", &n, &k) && n) {
        for(int i = 0; i < n; ++i) scanf("%d", a + i);
        int sum = 0, ans = -INF;
        for(int i = 0; i < n; ++i) {
            sum += a[i];
            if(i < k - 1) continue;
            if(i >= k) sum -= a[i - k];
            ans = max(ans, sum);
        }
        printf("%d\n", ans);
    }
}

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

int main()
{
	int n, k, i, inp, sum, max=0;
	int *a;
	cin >> n >> k;
	a = new int[n];
	
	for (i = 0; i < n; i++){
		cin >> inp;
		a[i] = inp;
	}
	
	for (i = 0; i < n - 2; i++){
		sum = a[i] + a[i + 1] + a[i + 2];
		if (sum > max){ max = sum; }
	}

	cout << max << endl;

	delete[] a; 
	return 0;
}

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

using namespace std;

int main( void )
{
	int n, k, input[5000];
	while(cin >> n >> k, n | k) {
		int sum = 0;
		for(int i=0; i < n; ++i) {
			cin >> input[i];
			if(i < k) sum += input[i];
		}
		int i, j, ans = sum;
		i = 0; j = k-1;
		while(j < n-1) {
			sum -= input[i++];
			sum += input[++j];
			ans = max(ans, sum);
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

C++: #include<iostream>
#include<limits.h>

#define N 100000
int n, k;
int a[N];

int input(){
	int i;
	std::cin >> n >> k;
	for( i = 0; i < n; i++ ){ std::cin >> a[i]; }
	return n;
}

int func(){
	int sum = 0, m = 0, i;
	for( i = 0; i < k; i++ ){ sum += a[i]; }
	m = sum;
	for( i = k; i < n; i++ ){
		sum += a[i] - a[i-k];
		m = (sum>m?sum:m);
	}
	return m;
}

int main(){
	while( input() > 0 ){ std::cout << func() << std::endl; }
	return 0;
}

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

#define repeat(n, i) for(int i=0;i<(n);i++)

int n, k;
vector<int> a;

int solve() {
    int sum = 0, prev_sum = 0;
    for (int i = 0; i < k; i++) {
        prev_sum += a[i];
    }
    int max_sum = prev_sum;
    for (int i = 1; i + k - 1 < n; i++) {
        sum = prev_sum - a[i-1] + a[i+k-1];
        if (max_sum < sum) max_sum = sum;
        prev_sum = sum;
    }
    return max_sum;
}

int main() {
    while (cin >> n >> k) {
        if (n == 0 && k == 0) break;
        a.clear();
        repeat(n, i) {
            int _a; cin >> _a;
            a.push_back(_a);
        }
        cout << solve() << endl;
    }
    return 0;
}