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;

int N, K;
vector<int> DpSum;

int solve() {
	int sum;

	sum = -1000000001;
	for (int i = 1; i + K <= N; ++i) {
		sum = max(sum, DpSum[i + K] - DpSum[i]);
	}

	return sum;
}

int main() {
	int a;

	while (cin >> N >> K, N) {
		DpSum.clear();
		DpSum.resize(N + 1);
		DpSum[0] = 0;
		for (int i = 1; i <= N; ++i) {
			cin >> a;
			DpSum[i] += DpSum[i - 1] + a;
		}
		cout << solve() << endl;
	}

	return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, k;
ll a[111111];

int main()
{
  while(cin >> n >> k, n){
    rep(i, n) cin >> a[i];

    rep(i, n - 1) a[i + 1] += a[i];

    ll res = a[k - 1];
    rrep(i, k, n) maxup(res, a[i] - a[i - k]);
    cout << res << endl;
  }

  return 0;
}

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

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


int main(){
    while (1){
	vector<int> inp;
	int n, k, input;
	cin >> n >> k;
	if (!(n || k)) break;

	for (int i = 0; i < n; i++){
	    cin >> input;
	    inp.push_back(input);
	}
	
	int right = inp.size(), left = 0, sum = 0;
	for (int i = 0; i < inp.size(); i++) sum += inp[i];
	
	while (right - left >= k){
	    if (inp[right] > inp[left]){
		sum -= inp[left];
		left++;
	    }
	    else {
		sum -= inp[right];
		right--;
	    }
	}
	cout << sum << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n, k;
		double a[100001] = {}, b[100001] = {} ,ans;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int i = 1; i <= n; i++){
			if (a[i + 2] == 0) break;
			b[i] = a[i] + a[i + 1] + a[i + 2];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<chrono>
#include<string>
#include<chrono>

using namespace std;






int main() {

	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	






	
	
	//system("pause");
	return 0;
}

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


int main(){
  int n, k;
  int a[100100];
  int b[100100];
  for(;;){
    cin >> n >> k;
    if(n==0 && k==0) break;
    
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    b[0] = 0;
    for(int i=0; i<n; i++){
      b[i+1] = b[i] + a[i];
    }
    int mx = -100000;
    for(int i=0; i<n-k+1; i++){
      int s = b[i+k] - b[i];
      if(mx < s) mx = s;
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k,x=0,ma=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-k;i++){
		x=0;
		for(int j=0;j<k;j++){
			x+=a[i+j];
		}
		ma=max(ma,x);
	}
	cout<<ma<<endl;
return 0;
}

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

using namespace std;

int main(){
  int a,b;
  long int ant,kazu[100000],maxt;
  while(1){
    maxt=0;
    scanf("%d%d",&a,&b);
    if(a==0&&b==0) return 0;
    for(int i=0;i<a;i++)scanf("%ld",&kazu[i]);
    for(int i=0;i<b;i++) maxt=maxt+kazu[i];
    ant=maxt;
    for(int i=0;i<a-b;i++) {maxt=max(maxt,ant-kazu[i]+kazu[i+b]); 
      ant=ant-kazu[i]+kazu[i+b];
    }
    printf("%ld\n",max(maxt,ant));
  }
  
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

// #define int long long

/* cpp template {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  for (int n, k; cin >> n >> k, n || k; ){
    vi sum(n + 1, 0);
    cin >> sum[1];
    REPS(i, 2, n + 1) cin >> sum[i], sum[i] += sum[i - 1];

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

  return (0);
}

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

int main(){
  int n,k,p,ans=0,sum=0;
  cin>>n>>k;

  while(n!=0&&k!=0){
    vector<int> v;
    for(int i=0;i<n;i++){
      cin>>p;
      v.push_back(p);
    }
    for(int i=0;i<=n-k;i++){
      for(int j=0;j<k;j++){
        sum+=v[i+j];
      }
      if(sum>=ans){
        ans=sum;
      }
      sum=0;
    }
    cin>>n>>k;
    cout<<ans<<endl;
  }
  return 0;
}