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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



int main() {

	while (true) {
		int n, k, ans = 0;
		int a[100002], b[100002];
		cin >> n >> k;
		if (n == 0 && k == 0)break;
		rep(i, n)cin >> a[i];
		b[0] = 0;
		REP(i, 1, n + 1)b[i] = b[i - 1] + a[i - 1];

		REP(i, k, n + 1)ans = max(ans, b[i] - b[i - k]);

		cout << ans << endl;
	}

	return 0;
}

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

int main(void)
{
  int n, k;
  int max;
  int sum;
  int* num_sequence;
  while (true)
  {
    cin >> n >> k;
    if ( n == 0 && k == 0 ) break;

    //int* num_sequence = new int[n];
    num_sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
      cin >> num_sequence[i];
    }

    max = -999999;
    for (int j = 0; j < n-k+1; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    delete[] num_sequence;
  }
  return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;
    int ans = -50000;
    int sum = 0;
    int lastNum;
    vi series;
    cin >> n >> k;

    for(int i=0; i < n; i++){
        int m;
        cin >> m;
        series.push_back(m);

        if(i < k-1) sum += m;
        else {
            sum += m-series[i-k];
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll n,k;
ll val[100000];
ll sum[100000];
int main()
{while(1){
	memset(val,0,sizeof(val));
	memset(sum,0,sizeof(sum));
	cin>>n>>k;
	if(!n) return 0;
	for(ll i=0;i<n;i++) cin>>val[i];
	for(ll i=0;i<k;i++) sum[0]+=val[i];
	ll ans=sum[0];
	for(ll i=1;i<=n-k;i++){
		sum[i]=sum[i-1]-val[i-1]+val[i+k-1];
		ans=max(ans,sum[i]);
	}
	cout<<ans<<endl;
}}

C++: #include <cstdio>

using namespace std;

int n,k,s,smax;
int a[100000];
int s1,s2;

int main(){
	scanf("%d %d\n",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
		printf("%d\n",smax);
	return 0;
}

C++: #include <iostream>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(void){
	int n,k;
	int a[100000];
	int sum=0;
	int m=0;
	while (cin>>n>>k,n||k) {
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<k;i++)sum+=a[i];
		m=sum;
		for(int i=k+1;i<n;i++){
			sum-=a[i-k-1];
			sum+=a[k];
			m=MAX(sum,m);
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: //aoj0516 in binary indexed tree

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

int n, k;
int a[100010];
int ans = 0;

struct bittree
{
  int tree[100010];

  void reset()
  {
    memset(tree, 0, sizeof tree);
  }
  
  void add(int where, int val)
  {
    for(int i = where; i <= n; i += i & -i){
      tree[i] += val;
    }
  }

  int sum(int where)
  {
    int ret = 0;
    
    for(int i = where; i >= 1; i -= i & -i){
      ret += tree[i];
    }

    return ret;
  }
} tr;

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

    tr.reset();
    
    for(int i = 1; i <= n; i++){
      tr.add(i, a[i]);
    }

    for(int i = 1; i <= n - k + 1; i++){
      ans = max(ans, tr.sum(i + k - 1) - tr.sum(i - 1));
    }

    cout << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			if (data[i] < 0) data[i] *= 2;
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			int tmp = data[i + k] - data[i];
//			for (int j = i; j < (i + k); j++){
//				if (data[j] < 0) tmp += data[j];
//			}
			max = MAX(max, tmp);
		}
		
		/*
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}*/
		
		printf("%d\n", max);
	}
	
	return (0);
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;
    int ans = -50000;
    vi series;
    cin >> n >> k;
    for(int i=0; i < n; i++){
        int m;
        cin >> m;
        series.push_back(m);
        int sum = 0;
        if(2 < i){
            for(int j=0; j < 3; j++){
                sum += series[i-j];
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;

}

C++: #include <iostream>
using namespace std;
const int SIZE=100001;
int a[SIZE]={00},b[SIZE]={00},c[SIZE]={00};

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

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


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

	for (long long i = 0; i < n; i++){
	    cin >> input;
	    inp.push_back(input);
	}
	
	long long right = inp.size(), left = 0, sum = 0;
	for (long long 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;
    }
}