Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0516 : Maximum Sum **/
int main()
{
	int N, K;
	while (cin>>N>>K) {
		vector<int> a(N);
		rep(i, N) cin>>a[i];
	
		int k=0;
		rep(i, K) k+=a[i];
	
		
		int ans=k;
		REP(i, K, N) {
			k+=a[i]; k-=a[i-K];
			ans = max(ans, k);
		}
		cout << ans << endl;
	}
}

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

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

void solve16(int a, int b) {
    vector<int> v;
    REP(i,a) {
        int j;
        cin >> j;
        v.push_back(j);
    }
    vector<long> vl;
    long s = 0;
    REP(i, b) {
        s += i;
    }
    vl.push_back(s);
    REP(i,a-b) {
        s -= v[i];
        s += v[b+i];
        vl.push_back(s);
    }
    sort(vl.begin(), vl.end(), greater<long>());
    cout << vl[0] << endl;
}

int main() {
    int a, b;
    while(cin >> a >> b, a+b) {
        solve16(a, b);
    }
    return 0;
}

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

using namespace std;

int main(){
  while(true){
    int a[100000] = {0};
    int n, k;
    cin >> n >> k;
    if(!n)
      break;
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int ans = 0;
    for(int j = 0; j < k; j++){
      ans += a[j];
    }
    int ab = ans;  
    //cout << "f:" << aa << endl;
    for(int i = k; i < n; i++){
      int aa = ab - a[i - k] + a[i];
      ab = aa;
      ans = aa > ans ? aa : ans;
      //cout << aaa << ":" << aa << " - " << a[i - k] << " + " << a[i] << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

using namespace std;

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

C++: int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * n);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == n) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
    }

    cout << max << endl;
    }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n , k;
    cin >> n >> k;
    while(n!=0|| k!=0){
    vector<int>a(n);
    for(int i = 0;i < n;i++){
      cin >> a.at(i);
    }
   vector<int>S(n+1);
   S.at(0) = 0;
   for(int i = 0;i < n+1 ;i++){
     S.at(i+1) = S.at(i) + a.at(i);
   }
   int ans = 0;
   for(int i = 0;i+k < n+2;i++){
     if(S.at(i+k)-S.at(i) > ans)
     ans = S.at(i+k) - S.at(i);
   }
   cout << ans << endl;
   cin >> n >> k;
    }
 }

C++: #include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int main(){
	int i,i2,sum,ans=0,n,k;
	cin>>n>>k;
	for(i=0;i<n;i++)cin>>a[i];
	for(i=0;i<n-k;i++){
		sum=a[i];
		for(i2=1;i2<k;i2++)sum+=a[i+i2];
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int num[100001];
int main(void){
   int n,k;
   while(scanf("%d%d",&n,&k),n+k){
      for(int i = 0;i < n;i++){
         scanf("%d",&num[i]);
      }
      int ma = -2000000011;
      for(int i = 0;i <= n-k;i++){
         int part_ma = 0;
         for(int j = i;j < i+k;j++){
            part_ma += num[j];
         }
         ma = max(ma,part_ma);
      }
      printf("%d\n",ma);
   }
   return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	while(1){
	int n,k,ans=0;
	cin>>n>>k;
	if(n==0 && k==0){
		break;
	}
	int a[n+2];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-3;i++){
		int cnt=0;
		for(int j=0;j<k;j++){
		cnt=cnt+a[i+j];
		}
		ans=max(cnt,ans);
	}
	cout<<ans<<endl;
	}

	return 0;
	

}

C++: #include<stdio.h>

int MAX(int *num,int n,int k){
	int i,j,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	for(i = 1;i < n-k;i++){
		now = 0;
		for(j = 0;j < k;j++){
			now += num[i+j];
		}
		if(max < now)
			max = now;
	}
	return max;
}
//更新書き換え型
/*int MAX(int *num,int n,int k){
	int i,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	now = max;
	for(i = 0;i < n-k;i++){
		now += num[i+k]-num[i];
		if(max < now)
			max = now;
	}
	return max;
}*/
int main(){
	int n,k,max;
	int *num;
	int i;
	while(1){
		scanf("%d%d",&n,&k);
		if(n == 0 && k == 0)
			break;
		num = new int[n];
		for(i = 0;i < n;i++){
			scanf("%d",num+i);
		}
		max = MAX(num,n,k);
		printf("%d\n",max);
		delete[] num;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  while (1) {
    int k, n;
    cin >> n >> k;
    if ((k <= n) && (n == 0)) {
      return 0;
    }

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

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