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;
using ll = long long;

int main() {
  for (int i = 0; i < 5; i++) {
    int n, k;
    cin >> n >> k;

    // プログラム終了の合図
    if (n == 0 && k == 0) {
      return 0;
    }

    // 累積和
    vector<int> s(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      int num;
      cin >> num;
      s.at(i) = s.at(i - 1) + num;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      int left = i;
      int right = i + k;

      if (right > n) {
        break;
      }

      int dif = s.at(right) - s.at(left);
      ans = max(ans, dif);
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int a,b=0,t,j,k,n,i,s[100000+1],v,c[100000+1]={0};
	while(1)
	{
		cin>>n>>k;
		if(n==0&&k==0)
		{
			break;
		}
		for(i=0;i<n;i++)
		{
			cin>>s[i];
		}
		v=n-k+1;
		for(i=0;i<v;i++)
		{
			for(a=i;a<k+i;a++)
			{
				c[i]=c[i]+s[a];

			}
		}
		for(i=0;i<v;i++)
		{
			if(b<c[i])
			{
				b=c[i];
			}
		}
		cout<<b<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

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

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

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

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

int main()
{
  ll n, k;
  while (cin>>n>>k){
    if (n == 0) continue;

    ll sum = -INF;
    vector<ll> a(n);
    rep(i, n) cin>>a[i];

    vector<ll> s(n+1, 0);
    rep(i, n) s[i+1] = s[i] + a[i];

    for(int i=0; i < n-k; i ++){
      ll tmp = s[i+k] - s[i];
      if (sum < tmp) sum = tmp;
    }
    cout << sum << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k;
ll a[100100];
ll sum[100100];

int main(){
	while (cin >> n >> k&&n + k){
		fill(a, a + 100100, 0);
		fill(sum, sum + 100100, 0);
		ll MAX = -1000000000;
		REP(i, n)cin >> a[i];
		REP(i, n){
			if (i == 0)sum[i] = a[i];
			else sum[i] = sum[i - 1] + a[i];
		}
		REP(i, n - k + 1){
			sum[i + k] -= sum[i];
		}
		FOR(i, k - 1, n){
			MAX = max(MAX, sum[i]);
		}
		cout << MAX << endl;
	}
}

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

using namespace std;

class bit{
	
	public:
	vector<int> v;
	int n;

	bit(int arg){
		n = arg;
		//initially all nodes are 0
		for(int i=0;i<n+1;i++){
			v.push_back(0);
		}
	}
	
	int sum(int i){
		int s = 0;
		while(i>0){
			s += v[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, int x){
		while(i <= n){
			v[i] += x;
			i += i & -i;
		}
	}
};

int main(void){
	int n,k;
	
	while(cin >> n >> k){
		if((n|k) == 0) break;
		
		bit b = bit(n);
		int tmp;
		vector<int> sumvec;

		//construct Binary Index Tree
		for(int i=1;i<=n;i++){
			cin >> tmp;
			b.add(i,tmp);
			//cerr << "added " << tmp << endl;
		}
		
		sumvec.push_back(0);
		//calculate sum
		for(int i=1;i<=n;i++){
			sumvec.push_back(b.sum(i));
			//cerr << sumvec[i] << endl;
		}
		
		int maxi = 0;
		for(int i=1;i<=n-k;i++){
			maxi = max(maxi, sumvec[i+k] - sumvec[i]);
		}
		
		cout << maxi << endl;
	}
}

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

using namespace std;

int suretu[100000];

int ret_maxsum(int n, int k)
{
	int temp = 0;
	int max = 0, cont = 0;
	
	for(int i = 0; i < n-k+1; i++){
		for(int j = 0; j < k; j++){
			temp += suretu[cont+j];
//			printf("suretu%d = %d\n",j,suretu[cont+j]);
		}
//		cout << "**" << endl;
		if(temp > max){
//			printf("*maxツ更ツ新\n");
			max = temp;
		}
		temp = 0;
		cont++;
	}
	
	return max;
}
	

int main()
{
	for(;;){
		int n,k;
		
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		
		cout << ret_maxsum(n, k) << endl;
	}
	
}

C++: #include <iostream>
using namespace std;
int main()
{
  int n,k;
  for(;cin>>n>>k,n;)
    {
      int d[n];
      for(int i=0;i<n;i++)
	cin>>d[i];
      int sum=0;
      int i;
      for(i=0;i<k;i++)
	{
	  sum+=d[i];
	}
      int max=sum;
      for(;i<n;i++)
	{
	  sum+=d[i];
	  sum-=d[i-k];
	  if(max<sum)
	    max=sum;
	}

      cout<<max<<endl;
    }
}

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


int sum(int a[], int num) {
  int tmp = 0;
  for(int i = 0; i < num; i++) {
    tmp += a[i];
  }
  return tmp;
}

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

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){
    for(;;){
	int n,k;
	int sum=0,sum2=0;
	int a[100010]={0};
	cin >> n;
	cin >> k;
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++){
	    cin >> a[i];
        }
    for(int i=0;i<n-k+1;i++){
        sum=0;
        for(int j=0;j<k;j++){
            sum +=a[j+i];
        }
        if(sum2<sum)sum2=sum;
    }
    cout << sum2 << endl;

    }


	return 0;
}

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

using namespace std;

int a[100000 + 1];
int s[100000 + 1];

int main() {

	int n, k;
	int i, j, l;
	int sum = 0, asus = 0;

	while (true) {

		memset(s, 0, sizeof(s));
		memset(a, 0, sizeof(a));

		cin >> n >> k;
		if (n == 0 && k == 0) return 0;

		for (i = 0; i < n; ++i) cin >> a[i];

		for (i = 0; i < n-k; ++i) {
			for (j = 0; j < k; ++j) {

				sum += a[i + j];
			}
			asus = max(asus, sum);
			sum = 0;
		}

		cout << asus << endl;
	}
}

C++: #include <cstdio>

int n,k,a;
long long dp[100000];

int main(){
	while(scanf("%d%d",&n,&k), n != 0){
		for(int i = 0; i < n; i++) dp[i] = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&a);
			if(i == 0){
				dp[i] = a;
			}
			else{
				dp[i] = dp[i-1] + a;
			}
		}
		long long mx = 0;
		for(int i = 0; i <= n - k; i++){
			long long sum = dp[i+k] - dp[i];
			if(sum > mx){
				mx = sum;
			}
		}
		printf("%lld\n",mx);
	}
	return 0;
}