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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	int K;
	while(cin>>n>>K,n){
		vll v(n);
		rep(i,n) cin>>v[i];
		ll cnt=0;
		ll ans=-INFL;
		ll sum=0;
		rep(i,n){
			if(cnt<K){
				sum+=v[i];
			}
			else{
				sum+=v[i]-v[i-K];
			}
			maxs(ans,sum);
		}
		cout<<ans<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

using namespace std;
typedef long long ll;

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

    ll ans, sum = 0;
    for (int i = 0; i < k; i++) {
      sum += a[i];
    }
    ans = sum;

    for (int i = 0; i < n - k; i++) {
      sum += a[i + k] - a[i];
      ans = max(ans, sum);
    }

    cout << ans << endl;
  }

  return 0;
}

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

int N,K;
int a[10001];

void solve(){
    for(int i=0;i<N;i++){
        scanf("%d",&a[i+1]);
        a[i+1]+=a[i];
    }
    int ma=0;
    for(int i=K;i<=N;i++)ma=max(ma,a[i]-a[i-K]);
    printf("%d\n",ma);
}
int main(){
    while(scanf("%d%d",&N,&K),N||K)solve();
}

C++: //超都観光

#include "bits/stdc++.h"

using namespace std;

#define int long long

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int dp[100010];

signed main()
{
    while(true)
    {
    int N,K;
    cin >> N >> K;
    
    if(N == 0 && K ==0 ) break;

    int s = 0;

    REP(i, N)
    {
        int a;
        cin >> a;
        s += a;
        dp[i] = s;
    }

    int maxx = 0;

    REP(i, (N - K))
    {
        maxx = max(dp[i + K] - dp[i], maxx);
    }

    cout << maxx << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値

int main() {
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        // 累積和を前計算
        vector<int> s(N+1, 0);
        for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        // 答えを求める
        long long res = -INF; // 最初は無限小の値に初期化しておく
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0){
      break;
    }
    outp.resize(a+1,0);
    outp[a] = 0;
    gh = 0;
    vector<int> num(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num[n];
    }
    for(int n = 0;n<serchn;n++){
      outp[a] += num[n];
    }
    gh = outp[a];
    for(int a = 0,b=serchn;b<numn;a++,b++){
      gh += num[b];
      gh -= num[a];
      if(gh > outp[a])outp[a] = gh;
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  return 0;
}

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;
    if(n==0 && k==0) break;
  
    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<bits/stdc++.h>
using namespace std;
int n,k,box[10000]={0},ans=0,sum=0,summ;
int main(){
    cin >> n >> k;
    while(1){
        for(int i=0;i<k;i++){
            cin >> box[i];
            if(box[0]==0&&box[1]==0)break;
            sum+=box[i];
            }
            if(box[0]==0&&box[1]==0)break;
          for(int i=k;i<n;i++){
                cin >> box[i];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    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 ] ;
			}

			if( i >= if_k )
			{
				ans = max( ans ,sum ) ;
			}
		}


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

C++: #include<iostream>

using namespace std;

int main(){

  int in, k;

  while(cin >> in >> k){
    if(in == 0 && k == 0) break;
    int data[in];
    int sum = 0;

    for(int i = 0; i < in; i++){
      cin >> data[i];
    }

    for(int i = 0; i <= in-k; i++){
      if(sum < data[i] + data[i+1] + data[i+2]) sum = data[i] + data[i+1] + data[i+2];
    }

    cout << sum << endl;
  }
  return 0;
}