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;
typedef long long ll;

// 1indexed1dimention[l,r]
class imos1d{
    public:
    vector<ll>t, v;
    ll num;
    ll flg;
    imos1d(ll NUM = 0){
        flg = 0;
        num = NUM + 10;
        v = vector<ll>(num, 0);
        t = vector<ll>(num, 0);
    }
    void add(ll idx, ll x){
        flg = 0;
        t[idx] += x;
    }
    void make(){
        flg = 1;
        for(ll i = 1; i < num; i++)v[i] = v[i - 1] + t[i];
    }
    ll sum(ll l, ll r){
        if(!flg)make();
        return v[r] - v[l - 1];
    }
};

class bit1d{
    public:
    vector<ll>v;
    ll num;
    bit1d(ll NUM = 0){
        num = NUM + 10;
        v = vector<ll>(num, 0);
    }
    void add(ll idx, ll x){
        if(idx == 0)return;
        while(idx <= num){
            v[idx] += x;
            idx += idx & -idx;
        }
    }
    ll sum_of_1_to_idx(ll idx){
        if(idx <= 0)return 0;
        ll s = 0;
        while(idx > 0){
            s += v[idx];
            idx -= idx & -idx;
        }
        return s;
    }
    ll sum(ll l, ll r){
        return sum_of_1_to_idx(r) - sum_of_1_to_idx(l - 1);
    }
};

int main(){
    
    for(ll N, K; cin >> N >> K, N;){
        imos1d data(N);
        for(ll i = 1; i <= N; i++){
            ll x;
            cin >> x;
            data.add(i, x);
        }
        ll ans = data.sum(1, K);
        for(ll l = 1, r = K; r <= N; l++, r++){
             ll tmp = data.sum(l, r);
             ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
    
    return 0;
}

C++: #include<stdio.h>

#include<algorithm>


using namespace std ;



int main()
{
	int n ,k ;

	while( 1 )
	{
		scanf( "%d %d" ,&n ,&k ) ;


		if( !( n | k ) )
		{
			return 0 ;
		}


		int if_k = k - 1 ;

		int ans = -10001 ,other[ 100000 ] ;
		
		int sum = 0 ;

		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&other[ i ] ) ;

			sum += other[ i ] ;


			if( i > if_k )
			{
				sum -= other[ i - k ] ;
			}


			ans = max( ans ,sum ) ;
		}


		printf( "%d\n" ,ans ) ;
	}
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;scanf("%d %d",&N,&K);for (i=0;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];ans=j,i=0,N-=K;while (N--) {j-=RB[i];scanf("%d",&RB[i]);j+=RB[i];if (ans<j) ans=j;i=(i+1)%K;} printf("%d\n",ans);return 0;}

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

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

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<stdio.h>

int main(void){
	int i,n,k,sum,max;
	int N[15000];

	while(0==0){
		scanf("%d %d",&n,&k);
		sum=0;
		if(n==0 && k==0) break;

		for(i=0;i<n;i++)
			scanf("%d",&N[i]);

		for(i=0;i<k;i++)
		    sum+=N[i];//初期値
		
		max=sum;

		for(i=k;i<n;i++){
			sum+=N[i];
			sum-=N[i-k];//前回のｋ個の連続した数の合計から次のｋ個の連続した数こ合計を計算する
			if(sum>max)max=sum;
		}

		printf("%d\n",max);
	}
	return 0;
}

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

int main(){
	int n,k,max,buf,*a;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			for(int i = 0; i <= n-k; i++){
				buf = 0;
				
				for(int j = 0; j < k; j++){
					buf += a[i+j];
				}
				
				if(max < buf){
					max = buf;
				}
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	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)*a[i-k],i++,k<i&M<s&&(M=s))std::cin>>a[i];
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int n;
int k;
int b;
int c;//現在の和
int d;//最高値
while(cin>>n){
if(n==0){break;}
cin>>k;
int a[n];
b=0;
while(b<n){
cin >>a[b];
b=b+1;}
c=0;
b=0;
while(b<k){
c=c+a[b];
b=b+1;}
d=c;
while(b<n){
c=c-a[b-k]+a[b];
if(c>d){d=c;}
b=b+1;}
cout << d<<endl;}
}

C++: #include <iostream>

using namespace std;

int main()
{
  int n, m, a[100000], t, s;

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

    t = s = 0;
    for(int i = 0; i < m; i++){
      t += a[i];
    }
    s = t;
    for(int i = m; i < n; i++){
      t += (a[i] - a[i-m]);
      if(s < t){
	s = t;
      }
    }
    cout << s << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int main() {
	int n, k;
	while (scanf("%d %d",&n,&k)&&n!=0) {
		vector<int> a(n);
		for (int i=0; i<n; i++) scanf("%d",&a[i]);
		int max=0;
		for (int i=0; i<n-k; i++) {
			int tmp=0;
			for (int j=i; j<i+k; j++) {
				tmp+=a[j];
			}
			if (tmp>max) max=tmp;
		}
		printf("%d\n",max);
	}
}

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

int main(){
    int n, k;
    while(true){
        if(cin >> n >> k){
            if(n == 0){
                break;
            }
            int a[n], b[n];
            for(int i = 0; i < n; i++){
                cin >> a[i];
                if(i == 0){
                    b[i] = a[i];
                }else{
                    b[i] = b[i - 1] + a[i];
                }
            }
            int ans = -1073741820;
            for(int i = 0; i < n - k; i++){
                if(ans <= b[i + k] - b[i]){
                    ans = b[i + k] - b[i];
                }
            }
            cout << ans << endl;
        }else{
            break;
        }
    }
    return 0;
}

C++: #include<iostream>

const int MAX_N = 1 << 17, INF = 1 << 24;

class SegmentTree{
public:
	SegmentTree(int _n){
		n = 1;
		while(n < _n)n *= 2;
		for(int i=0;i<2*n-1;i++){
			data[i] = 0;
		}
	}

	void add(int k, int a){
		k += n - 1;
		data[k] = a;
		while(k > 0){
			k = (k-1) / 2;
			data[k] = data[k*2+1] + data[k*2+2];
		}
	}

	int calculate(int a, int b){
		return _calculate(a, b, 0, 0, n);
	}
private:
	int data[MAX_N];
	int n;
	int _calculate(int a, int b, int k, int l, int r){
		if(r <= a || b <= l)return 0;

		if(a <= l && r <= b)return data[k];
		else{
			int l_child = _calculate(a, b, 2*k+1, l, (l+r) / 2),
				r_child = _calculate(a, b, 2*k+2, (l+r) / 2, r);
			return l_child + r_child;
		}
	}
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		SegmentTree st(n);
		for(int i=0;i<n;i++){
			int a_i;
			std::cin >> a_i;
			st.add(i, a_i);
		}

		int res = -INF;

		for(int i=0;i+k-1<n;i++){
			res = std::max(res, st.calculate(i, i+k));
		}

		std::cout << res << std::endl;
	}
}

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<k;i++) ans += num[i];
		int sum = ans;
		for(int i=1;i<n-k+1;i++){
			sum -= num[i-1];
			sum += num[i+k-1];
			ans = max(ans,sum);
		}
		cout << ans << endl;
	}
}