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<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)


int main(){


	while(true){
		int n,k,s;
		cin >> n >> k;
		if(n==0 && k==0) break;

	    vector<int>a;
        int sum=0; int m;
		rep(i,k){
		cin >> s;
		a.push_back(s);
		sum+=a[i];
		}

		m=sum;

		REP(i,k,n-1){
		cin >> s;
		a.push_back(s);
		sum+=a[i]-a[i-k];
		if(m<=sum) m=sum;

		}

		cout << m << endl;

		a.clear();

	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		vector<long long> sum;
		long long num[n];
		rep(i,n)cin>>num[i];
		rep(i,n-k+1){
			long long alt=0;
			loop(j,i,i+k){
				alt+=num[j];
			}
			sum.push_back(alt);
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int n[100000];
int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)return 0;
		int temp=0;
		for(int i=0;i<a;i++){
			int val;
			scanf("%d",&val);
			n[i]=(temp+=val);
		}
		int max=-1000000000;
		for(int i=0;i<a-b+1;i++){
			if(max<n[i+b]-n[i])max=n[i+b]-n[i];
		}
		printf("%d\n",max);
	}
}

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

using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main()
{
    int n,k;
    long long temp;
    long long ans;

    vector<long long> num;

    cin >> n >> k;
    while(n!=0 && k!=0) {
        for(int i=0; i<n; ++i) {
            cin >> temp;
            num.push_back(temp);
        }

        ans=0;

        for(int i=0; i<k; ++i) {
            ans+=num[i];
        }

        temp=ans;

        if(k!=n) {
            for(int i=k; i<n; ++i) {
                temp=temp+num[i]-num[i-k];
                ans=MAX(ans,temp);
            }
        }

        cout << ans << endl;
        num.clear();
        cin >> n >> k;
    }
    return 0;
}

C++: #include <algorithm>
#include <cstdio>
typedef long long ll;
ll dp[100000];
int v[100000];
int main()
{
    int n, k;
    while (scanf("%d%d", &n, &k), n|k) {
        for (int i=0; i<n; ++i) scanf("%d", v+i);
        dp[k-1] = 0;
        for (int i=0; i<k; ++i) dp[k-1] += v[i];
        for (int i=k; i<n; ++i) dp[i] = dp[i-1] - v[i-k] + v[i];
        printf("%lld\n", *std::max_element(dp+k-1, dp+n));
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n , k ,ans;
	double a[100001] = {}, b[100001] = {};
	cin >> n >> k;
	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;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N,k;
  while(cin >> N >> k && (N!=0 || k!=0)){
    int sum[N+1]={};
    int ans=-1*INF;
    for(int i=1;i<=N;i++){
      int a;
      cin >> a;
      sum[i]=sum[i-1]+a;
    }
    rep(i,N-k){
      int res=sum[i+k]-sum[i];
      chmax(ans,res);
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

vector<int> s;
int n, k;

int get_sum(int left, int right)
{
	return s.at(right) - s.at(left);
}

void get_ans(void)
{
	vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	s = vector<int>(n + 1, 0);
	for (int i = 0; i < n; i++)s.at(i + 1) = s.at(i) + a.at(i);
	int ans = get_sum(0, k);
	int tmp;
	for (int i = 1; i < n; i++)
	{
		if (k + i == n)break;
		tmp = get_sum(i, k + i);
		if (tmp > ans)ans = tmp;
	}
	cout << ans << endl;
}

int main(void)
{
	while (1)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)break;
		get_ans();
	}
	return 0;
}

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

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

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

using namespace std;

int n,m;
int x,s;
int a[100000];

int main(void){

  while( cin >> n >> m , n || m ){

    for( int i = 0 ; i < n ; i++ ){
      cin >> a[i];
    }
    x = 0;
    for( int i = 0 ; i < n ; i++ ){
      x += a[i];
    }
    s = x;
    for( int i = 0 ; i < n - m ; i++ ){
      x -= a[i];
      x += a[i + m];
      if( s < x ) s = x;
    }

    cout << s << endl;

  }
  return 0;
}

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

using namespace std;

int main(){
  int a[100000] = {0};
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int aa = 0;
  for(int i = 0; i < k; i++){
    aa += a[i];
  }
  //cout << "f:" << aa << endl;
  for(int i = k; i < n; i++){
    int aaa = aa - a[i - k] + a[i];
    aa = aaa > aa ? aaa : aa;
    //cout << "f:" << aa << " n:" << aaa << endl;
  }
  cout << aa << endl;
  return 0;
}

C++: #include<cstdio>
#include<utility>
#include<algorithm>
#define INF INT_MAX/2-1
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int a[100000];
int main(){
	int n, k;
	while (scanf("%d%d", &n, &k), n){
		rep(i, n)
			scanf("%d", &a[i]);
		int Max = -INF;
		rep(i, n - k + 1){
			int sum = 0;
			rep(j, k){
				sum += a[i + j];
			}
			Max = max(Max, sum);
		}
		printf("%d\n", Max);
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 114514
using namespace std;




int main(){
	while (1) {
		long long n, k, now = 0, m = 0, i;
		long long a[100009];
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (i = 1; i <= k; i++) {
			now += a[i];
		}
		m = now;
		for (i = 1; i <= n - k; i++) {
			now = now - a[i] + a[i + k];
			if (now > m) m = now;
		}
		cout << m << endl;
	}
	return 0;
}

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

using namespace std;

int n,m;
int x,s;
int a[100000];

int main(void){

  while( cin >> n >> m , n || m ){

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

    cout << s << endl;

  }
  return 0;
}