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 <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(n+k==0) break;
		vi a(n);
		rep(i,0,n) cin>>a[i];
		int sum=0;
		rep(i,0,k) sum+=a[i];
		int MAX=sum;
		rep(i,k,n){
			sum=sum+a[i]-a[i-k];
			MAX=max(MAX,sum);
		}
		o(MAX);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
bool solve(){
    int arr[100001]={0};
    int N,K;
    scanf("%d%d",&N,&K);
    if(N==0&&K==0)return false;
    for(int i=0;i<N;i++){
        scanf("%d",&arr[i+1]);
        arr[i+1]+=arr[i];
    }
    int ma=INT_MIN;
    for(int i=0;i+K<=N;i++){
        ma=max(ma,arr[i+K]-arr[i]);
    }
    printf("%d\n",ma);
    return true;
}

int main(){
    while(solve());
}

C++: #include<bits/stdc++.h>

using namespace std ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int m ;
		cin >> m ;
		int num[ n ] ;
		for( int i  = 0 ; i < n ; i++ )
			cin >> num[ i ] ;
		int ans = 0 ;
		for( int i  = 0 ; i < n ; i++ )
		{
			int cnt = 0 ;
			for( int j = i ; j < m + i && m + i < n ; j++ )
				cnt += num[ j ] ;
			ans = max( ans ,cnt ) ;
		}
		cout << ans << endl ;
	}
	return 0 ;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	while(1){
        int n,k;
        int sum = 0,mx = 0;
        int ans[100000] = {0};
        cin >> n >> k;
        if(n == 0 && k == 0) break;
        for(int i = 0; i < n; i++) cin >> ans[i];
        for(int i = 0; i < k; i++){
            sum += ans[i];
        }
        mx = sum;
        for(int i = k; i < n; i++){
            sum += ans[i];
            sum -= ans[i-k];
            mx = max(mx,sum);
        }
        cout << mx << endl;
	}
	return 0;
}

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

long long int num[100100];


int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=0;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<100100;i++){
            num[i]=0;
            if(num[i+1]==0)break;
        }
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i<m)sum+=num[i];
        }
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        if(ans>=0)cout<<ans<<endl;
        else cout<<0<<endl;
        ans=0;
        sum=0;
        }
    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>
#include <cmath>
#include <cstdio>
using namespace std;
int n, k;
int a[1000000];
int s, t;
int main()
{
	cin >> n >> k;
	while(n*k!=0)
	{
		s=0;
		for(int i=0; i<k; i++)
		{
			cin >> a[i];
			s+=a[i];
			t=s;
		}
		for(int i=k; i<n; i++)
		{
			cin >> a[i];
			t=t+a[i]-a[i-k];
			s=max(s, t);
		}
		cout << s << endl;
		cin >> n >> k;
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,k;
    while(cin>>n>>k,n+k){
    vl dp(n);
    rep(i,n){
        int ujimatu; cin>>ujimatu;
        if(!i)dp[0]=ujimatu;
        else if(i<k)dp[i]+=ujimatu+dp[i-1];
        else dp[i]=dp[i-1]+ujimatu-dp[i-k];
    }
    ll ans=0;
    rep(i,n)cmax(ans,dp[i]);
    cout<<ans<<endl;
    }
}

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

using namespace std;

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

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

using namespace std;

int main(){


    int n,k,ans=0,ans2=0,mx=0;
    while(1){
    scanf("%d%d",&n,&k);
    if(n==0&&k==0)break;
    int num[n];
    //for(int y=0;y<n;y++){
      //  scanf("%d",&num[y]);
    //}
        for(int a=0;a<k;a++){
                cin >> num[a];
        ans+=num[a];
        }
        mx=ans;
    for(int j=k;j<n;j++){
            cin >> num[j];
        ans2=ans-num[j-k]+num[j];
        if(mx<=ans2){
            mx=ans2;
        }
    ans=ans2;
    ans2=0;
    }
    printf("%d\n",mx);
    mx=0;
    ans=0;
    }

return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long int sum[111111];
int main(void)
{
  while(1){
    int n,k;
    cin >> n >> k;
    if(!n && !k) break;
    for(int i = 1; i <= n; i++){
      int a;
      cin >> a;
      sum[i] = sum[i-1] + a;
    }
    long long int best = -11111111111;
    for(int i = 0; i + k <= n; i++){
      best = max(best,sum[i+k] - sum[i]);
    }
    cout << best << endl;;
  }
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        int ans = 0, sum = 0;;
        int inp;
        queue<int> rec;
        rep(i, n){
            if(i < m){
                cin >> inp;
                sum+= inp;
                rec.push(inp);
            }else{
                cin >> inp;
                sum+= inp - rec.front();
                rec.pop();
                rec.push(inp);
            }
            if(ans < sum && i >= m)
                ans = sum;
        }
        cout << ans << endl;
    }
}