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 <iostream>
using namespace std;

int data[100000]={0};

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n,k;
int a[100000];
int sum[100000];

void solve() {
  sum[0] = a[0];
  for(int i=1;i<n;i++) {
    sum[i] = sum[i-1] + a[i];
  }
  int res = sum[k-1];
  for(int i=0;i<=n-k;i++) {
    res = max(res,sum[i+k-1] - sum[i-1]);
  }
  cout << res << endl;
}

int main() {
  while(cin >> n >> k) {
    if(n==0 && k==0) break;
    for(int i=0;i<n;i++) {
      cin >> a[i];
    }
    solve();
  }
}

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

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

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

int sum(int S[], int begin, int end) {
    int ans = 0;
    for (int i = begin; i < end; ++i) {
        ans += S[i];
    }
    return ans;
}

int main() {

    int n, k;
    for (;;) {
        cin >> n >> k;
        if (n == 0 && k == 0) break;

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

        int m = n - k + 1;
        int tmp = 0;
        int ans = -1000000000;
        for (int i = 0; i < m; ++i) {
            int tmp = sum(S, i, i + k);
            if (ans < tmp) ans = tmp;
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n,k;
	while(cin>>n>>k && n && k){
		int s[200000];
		s[0]=0;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			s[i]=s[i-1]+x;
		}
		int ans=s[k];
		for(int i=0;i+k<=n;i++){
			ans=max(ans,s[i+k]-s[i]);
		}
		cout<<ans<<endl;
	}
}

C++: /**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@16:28

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){
                
                int n=0;
                int k=0;
                int all=0;
                int total=0, answer=0;
                vector<int> data(5000);

                cin >> n >> k;
                if(n==0 && k==0)break;
                
                for(int i=0; i<n; i++){
                        cin >> data[i];
                }
               

                for(int j=0; j<n-k; j++){
                        
                        if( j == 0){
                                for(int i=0; i<k; i++){
                                        total = total + data[j+i];
                                }
                        }else{
                                
                                total = total - data[j-1] + data[j+k-1];
                        }
                        
                        if( answer < total){
                                answer = total;
                        }
                        
                }
                
                cout << answer << endl;
                
        }

        return 0;

}

C++: #include <iostream>

int kk[100000];

int main(){

int s=0;
int n,k;
std::cin>>n>>k;

for(int i=0;i<k;i++){
std::cin>>kk[i];
s+=kk[i];
}

int st=s;

for(int i=k;i<n;i++){
std::cin>>kk[i];
s+=kk[i]-kk[i-k];
if(s>st)
st=s;
}

std::cout<<st<<std::endl;

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int n, k;
    while (cin >> n >> k, n) {
        vector<int> ac(n+1, 0);
        for (int i=1; i<=n; ++i) {
            cin >> ac[i];
            ac[i] += ac[i-1];
        }
        int res = -INT_MAX;
        for (int i=k; i<=n; ++i) {
            res = max(res, ac[i] - ac[i-k]);
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int N;
  cin >> N;
  //いもす！！
  vector<int> P(1000, 0);

  for(int i = 0; i < N; i++) {
    int s, e;
    cin >> s >> e;
    P[s]++;
    P[e]--;
  }
  //るいせきわ(=いたにんずう) 1ひいてつかう
  vector<int> S(1001);
  S[0] = 0;
  for(int i = 0; i < N; i++) {
    S[i + 1] = S[i] + P[i];
  }
  bool flag = true;
  for(int i = a; i <= b; i++) {
    if(S[i - 1] > 0) { flag = false; }
  }

  if(flag)
    cout << 0 << endl;
  else
    cout << 1 << endl;

  return 0;
}

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

long long int num[100100];

int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=0;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<100100;i++){
            num[i]=0;
            if(num[i+1]==0)break;
        }
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i<m)sum+=num[i];
        }
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        cout<<ans<<endl;
        ans=0;
        sum=0;
        }
    return 0;
}

C++: #include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

LL S[MAX_N+1],n,m;
LL ans;

class BIT{
    public:
        int N;
        void init(int _N){
            N=_N;
            rep(i,N+1)S[i]=0;
        }

        LL getSum(int i){
            LL s=0;
            while(i){
                s+=S[i];
                i-=i&-i;
            }
            return s;
        }

        void add(int i,int x){
            while(i<=N){
                S[i]+=x;
                i+=i&-i;
            }
        }
};

int main(){
    while(1){
        BIT bit;
        int t=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        bit.init(n);
        FOR(i,1,n){
            int x;
            cin>>x;
            bit.add(i,x);
        }
        FOR(i,m,n-m){
            LL query=bit.getSum(i)-bit.getSum(t);
            ans=max(query,ans);
            t++;
        }
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}