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;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int N, K;
int num[100000];
int tmp[100000];

int main() {
	while(scanf("%d %d", &N, &K), N || K) {
		rep(i, N) scanf("%d", &num[i]);
		FOR(i, 1, N) num[i] += num[i - 1];
		int ans = num[K - 1];
		FOR(i, K, N) ans = max(num[i] - num[i - K], ans);
		printf("%d\n", ans);
	}
	return 0;
}

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

template<typename T>
struct CumulativeSum {
    vector<T> s;
    CumulativeSum(const vector<T> &nums) {
        int n = nums.size();
        s.resize(n + 1, 0);
        for (int i = 0; i < n; ++i) {
            s[i + 1] = s[i] + nums[i];
        }
    }
    // [l, r), l and r is 0-indexed.
    T sum(int l, int r) {
        return s[r] - s[l];
    }
};

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/0516
*/
int main() {
    int n, k;
    vector< long long > ress;
    while (cin >> n >> k) {
        if (n == 0) break;
        vector<long long> nums(n);
        for (int i = 0; i < n; ++i) cin >> nums[i];
        CumulativeSum<long long> cs(nums);
        long long res = numeric_limits<long long>::min();
        for (int i = 0; i <= n - k; ++i) {
            long long val = cs.sum(i, i + k);
            res = max(res, val);
        }
        ress.push_back(res);
    }
    for (long long res : ress) cout << res << endl;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
    scanf("%d %d",&n,&k);
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    scanf("%d",&set[i]);
  }

  for(int i=0,sum=0;i<n-k+1;i++,sum=0){
    for(int j=i,l=i+k-1;;j++,l--){
      sum += set[j]+set[l];
      if(l-j==1){
	break;
      }else if(l==j){
	sum-=set[j];
	break;
      }
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  printf("%d\n",max);
  }
}

C++: #include <iostream>
using namespace std;
int main(){
	int s[100000];
	int n;
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int q=0;
	for(int i=0;i+k-1<=n;i++){
		int t=0;
		for(int ii=0;ii<k;ii++){
			t+=s[i+ii];
		}
		if(q<t)
			q=t;
	}
	cout<<q<<endl;
	return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, k;
    while(cin >> n >> k){
        if(n == 0 and k == 0) break;
        vector<int> A(n), B(n + 1, 0);
        for(int i = 0; i < n; i++){
            cin >> A[i];
            B[i + 1] += B[i] + (i > 0 ? A[i - 1] : 0);
        }

        int maxi = -1e9;
        for(int i = k; i < n + 1; i++){
            maxi = max(maxi, B[i] - B[i - k]);
        }
        cout << maxi << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

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

int main(){
  int n,k,x;
  vector<int> s;
  int start,end,ans=0,sum;
  
  while(1){

    cin>>n>>k;
    for(int i=0;i<n;i++){
      cin>>x;
      s.push_back(x);
    }
  
    start=0;end=k;
    while(end-1<n){
      sum=0;
      for(int i=start;i<end;i++){
        sum+=s[i];
      }
      ans=max(ans,sum);
    
      start++;end++;
    }
  
    printf("%d\n",ans);
    ans=0;
    s.clear();
  }
  return 0;
}

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

int a[MAX];

int main(void){
 	int n,k;
	while(cin >> n >> k,n|k){
		int ans=-1000000000;
		int cmax=0;
		for(int i=0;i<k;i++){
			cin >> a[i];
			cmax+=a[i];
		}
		ans=max(ans,cmax);
		for(int i=k;i<n;i++){
			cin >> a[i];
			cmax+=a[i];
			cmax-=a[i-k];
			ans=max(ans,cmax);
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n, k; n = in(), k = in(), k || n;) {
		int r = INT_MIN;
		vector<int> s(n + 1);
		for (int i = 1; i <= n; i++) {
			s[i] = s[i - 1] + in();
			if (i >= k)
				r = max(r, s[i] - s[i - k]);
		}
		outl(r);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
	while(1){
	int k,n,s=0,cn=0;
	cin>>k>>n;
	if(k==0 && n==0){
		break;
	}
	int dat[n+10];
	for(int i=0;i<k;i++){
		cin>>dat[i];
	}
	for(int j=0;j<k-n+1;j++){
		cn=0;
		for(int k=0;k<n;k++){
			cn+=dat[j+k];
		}
		s=max(s,cn);
	}
	cout<<s<<endl;
	}
	return 0;
}

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

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

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

int main()
{
    int n,m,a[100000];
for(;;){
cin >> n >> m;
if(n==0&&m==0)return 0;
for(int i=0;i<n;i++)cin >> a[i];
int ans=0;
int x=0;
for(int i=0;i<m;i++)x+=a[i];
ans=max(ans,x);
for(int i=0;i<n-m;i++){
x+=a[i+m];
x-=a[i];
ans=max(ans,x);
}
printf("%d\n",ans);
}
}