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>

using namespace std;

int main()
{
	int k,n;
	int a[100000];
	while (cin>>n>>k,n!=0&&k!=0) {
		long long sum=0,max;
		for (int i=0; i<n; i++) cin>>a[i];
		for (int i=0; i<k; i++) sum+=a[i];
		max=sum;
		for (int i=k; i<n; i++) {
			sum=sum+a[i]-a[i-k];
			if (sum>max) max=sum;
		}
		cout<<max<<endl;
	}
}

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

int main(){
    int n,k;
    while(cin>>n>>k){
        int total[100010]={0},ip[100010]={0};
        if(n==0 && k==0)break;
        for(int i=0;i<n;i++){
            cin>>ip[i];
            if(i==2)total[i]=ip[i-2]+ip[i-1]+ip[i];
            if(i>2){
                total[i]=total[i-1]-ip[i-3]+ip[i];
            }
        }
        sort(total, total+n, greater<int>());
        cout<<total[0]<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int n, k;
	int a[100000];

	while(cin >> n >> k) {
		if(n==0&&k==0) {
			break;
		}
		for(int i=0; i<n; i++) {
			cin >> a[i];
		}
		int max=a[0];
		int t=0;
		for(int i=0; i<k; i++) {
			t+=a[i];
		}
		if(t>max) {
			max=t;
		}
		for(int i=k; i<n; i++) {
			t+=a[i];
			t-=a[i-k];
			if(t>max) {
				max=t;
			}
		}
		cout << max << endl;
	}

	return 0;

}

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

int main(){
  int n,k,a[MAX];

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

    int MX = 0 , sum;
    for(int i = k-1 ; i < n ; i++){
      sum = 0;
      for(int j = i-k+1 ; j <= i ; j++){
	sum += a[j];
      }
      if(MX < sum) MX = sum;
    }
    cout << MX << endl;
  }

  return 0;
}

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

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

int seq[100000];
int n,k;

int req(int rem, int i)
{
	rem -= seq[i];
	rem += seq[i+k];
	return rem;
}
int main()
{
	while(cin >> n >> k){
		if(n==0&&k==0)
			break;
		for(int i=0;i<n;i++){
			cin >> seq[i];
		}
		int rem=0;
		for(int i=0;i<k;i++){
			rem+=seq[i];
		}
		int remm = rem;
		cout << rem << endl;
		for(int i=0;i<n-k;i++){
			rem = req(rem,i);
			remm = max(remm,rem);
		}
		cout << rem << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
typedef long long ll;

vector<string> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    while (cin >> n >> k, n || k)
    {
        ll arr[n + 1];
        for (int i = 0; i < n; ++i)
            cin >> arr[i];

        for (int i = 0; i < n; ++i)
        {
            arr[i + 1] += arr[i];
        }

        ll maxV = 0;
        for (int i = 0; i < n - k; ++i)
        {
            maxV = max(maxV, arr[i + k] - arr[i]);
        }
        cout << maxV << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i<n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        int x=S[k];
        for(int l=1;l<n-k;l++){
            if(x<S[k+l]-S[l]){
                x=S[k+l]-S[l];
            }
        }
        cout << x << endl;
        cin >> n >> k;
        

    }

}

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

int main(){
    int n;
    int k;

    while(cin >> n >> k, n != 0 || k != 0){
        vector<int> data;
        int sum = 0;
        for(int i=1; i<=n; i++){
            int tmp;
            cin >> tmp;
            data.push_back(tmp);
        }
        for(int i=0; i<k; i++){
            sum += data[i];
        }
        int max = sum;
        for(int i=3; i<data.size(); i++){
            sum -= data[i-3];
            sum += data[i];
            if(sum > max) max = sum;
        }
        cout << max << endl;
    }
    return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;

    while(cin >> n >> k, n+k){
        int ans = -50000;
        int sum = 0;
        vi series;
        for(int i=0; i < n; i++){
            int m;
            cin >> m;
            series.push_back(m);

            if(i < k-1) sum += m;
            else {
                sum += m-series[i-k];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(){


    int n,k,ans=0,ans2;
    while(1){
    cin >> n >> k;
    if(n==0&&k==0)break;
    int num[n];
    for(int y=0;y<n;y++){
        cin >> num[y];
    }
    for(int j=k;j<n;j++){
        for(int a=0;a<k;a++){
        ans+=num[j-k+a];
        }
        if(ans2<ans){
            ans2=ans;
        }
        ans=0;
    }
    cout << ans2 << endl;
    }

return 0;
}

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

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

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

using namespace std;

int n,k,s,ans,term,ans_t;
vector<int> a_n;
int m,t;

int main()
{

  while(1){
    m = 0;
    cin>>n>>k;

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

    for(int q = 0;q < n;++q){
      cin>>term;
      a_n.push_back(term);
    }

    for(int q = 0; q < n+1-k; ++q){
      s = q;
      ans_t = 0;

      while(1){
        if(s == k+q){
          break;
        }
        ans_t += a_n[s];
        ++s;
      }

      if(q == 0){
        ans = ans_t;
      }
      else{
        if(ans_t > ans){
          ans = ans_t;
        }
      }
    }

    cout<<ans<<endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<chrono>
#include<string>
#include<chrono>

using namespace std;






int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	







	return 0;
}