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<string.h>
#include<cstring>
#include<algorithm>

using namespace std;

int s[100000 + 1];
int r[100000 + 1];

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> s[i];

	r[0] = 0;
	for (int i = 0; i < n; i++) r[i + 1] = s[i] + r[i];

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

}

C++: #include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef priority_queue<int> PQ;

int main(){
	int n,k;

	while(true){
		int max=0;
		vector<int> a;

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

		for(int i=0;i<n;i++){
			int t;
			cin>>t;
			a.push_back(t);
		}

		for(int i=0;i<=n-k;i++){
			int t=i+k-1,s=0;
			for(int j=i;j<=t;j++){
				s+=a[j];
			}
			if(max<s) max=s;
		}

		cout<<max<<endl;

	}
	return 0;
}

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			if (data[j] < 0) data[j] *= 2;
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			int tmp = data[i + k] - data[i];
//			for (int j = i; j < (i + k); j++){
//				if (data[j] < 0) tmp += data[j];
//			}
			max = MAX(max, tmp);
		}
		
		/*
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}*/
		
		printf("%d\n", max);
	}
	
	return (0);
}

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

int main(){
  int n,k,a,s;
  while(cin>>n>>k,n||k){
    int m=-10001;a=0;
    queue<int> q;
    n-=k;
    while(k--){
      cin>>s;
      a+=s;q.push(s);
    }
    m=max(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>
#include<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max = 0, 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; 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;
int n=0, k=0;
double a[100001] = {}, b[100001] = {}, ans=0;
int main(){
while (cin>>n>>k){
n=0; k=0;
a[100001] = {}; b[100001] = {}; ans=0;
cin >> n >> k;
if (n == 0 && k == 0)	break;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
for (int x = 0; x<k; x++){
b[1] += a[1 + x];
}
ans=b[1];
for (int i = 2; i <= n; i++){
if (a[i + k - 1] == 0)	break;
b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
if (b[i]>b[i - 1]){
ans = b[i];
}
}
cout << ans << endl;
}
return 0;
}

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

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

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

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

		if (n==0&&k==0){ break; }
		else{
			int i, j, inp, max = 0;
			int a[100000];

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

			for (i = 0; i < n - k + 1; i++){
				int sum = 0;

				for (j = 0; j < k; j++){
					sum += a[i + j];
				}

				if (sum > max){ max = sum; }
			}

			cout << max << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k,x=0,ma=0;
	cin>>n>>k;
	int a[5];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n-k+1;i++){
		x=0;
		for(int j=0;j<k;j++){
			x+=a[i+k];
		}
		ma=max(ma,x);
	}
	cout<<ma<<endl;
return 0;
}

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

using namespace std;

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

C++: 
#include <stdio.h>
#include <stdlib.h>
#define MAX_n 100000
int main()
{
	int n,k,a[MAX_n],i,put=0,total=0;
	while(scanf("%d%d",&n,&k),n+k!=0)
	{
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i+k<=n;i++)
		{
			for(int j=i;j<i+k;j++)
				total+=a[j];
			if(put<total)
				put=total;
			total=0;
		}
		printf("%d\n",put);
		put=0;
	}
	//Sleep(10000);
}

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

constexpr int MAX_N= 100000;

int n,k;
int sums[MAX_N];

int main(){
    while(1){
    	std::cin>>n>>k;
    	if(n+k==0)
    		break;
    	for(int i=0;i<n;++i)
    		std::cin>>sums[i];
    	for(int i=1;i<n;++i)
    		sums[i]+=sums[i-1];
    	int ans=sums[k-1];
    	for(int i=0;i<n-k+1;++i)
    		ans=std::max(ans,sums[i+k]-sums[i]);  
    	std::cout<<ans<<std::endl;
    }
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(void){
	int a[100001];
	int n,k,sum,t;
	for(;;){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0)return 0;
		sum=t=0;
		for(int i=0;i<n;i++){
			scanf("%d",a+i);
			if(i>=k)t-=a[i-k];
			t+=a[i];
			//printf("t %d\n",t);
			sum=max(sum,t);
		}
		printf("%d\n",sum);
	}
}

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

int main(){

  int n, k;
  while( cin >> n >> k, n+k ) {
    int max_sum, sum, data[100000];
    
    cin >> data[0] >> data[1] >> data[2];
    max_sum = sum = data[0] + data[1] + data[2];
    
    for(int i=3; i<n; i++) {
      cin >> data[i];
      sum -= data[i-k];
      sum += data[i];
      max_sum = max(max_sum, sum);
    }

    cout << max_sum << endl;
  }
}

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

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

		if (n == 0 && k == 0){ break; }
		else{
			int i, inp;
			int *a;
			a = new int[n];

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

			int sum1 = 0, sum2 = 0, max = 0;

			for (i = 0; i<k; i++){ sum1 += a[i]; }
			max = sum1;

			for (i = k; i<n-k; i++){
				sum2 = sum1 + a[i] - a[i - k];
				if (sum2>max){ max=sum2; }
				sum2 = sum1;
			}

			cout << max << endl;

			delete[] a;
		}
	}
	return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> A(n);
  for (ll i = 0; i < n; i++) {
    cin >> A[i];
  }
  int tmp;
  cin >> tmp >> tmp;

  vector<ll> s(n);
  for (ll i = 0; i < n; i++) {
    s[i + 1] = s[i] + A[i];
  }
  ll mx = (1LL << 60) * -1;

  for (ll i = 0; i < n - k; i++) {
    mx = max(mx, s[i + k] - s[i]);
  }
  cout << mx << endl;
}