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<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a[100010] = {};
	for (int n, k; cin >> n >> k&&n;) {
		rep(i, 0, n) {
			cin >> a[i];
		}
		int ans = accumulate(a, a + k, 0);
		rep(i, k, n) {
			ans = max(ans, ans + a[i] - a[i - k]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int ans, tmp;

int main(void)
{
    int n, k;
    while(1) {
        cin >> n >> k;
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) cin >> a[i];
        ans = 0;
        for(int i=0; i<k; i++) ans += a[i];
        tmp = ans;
        for(int i=0; i<n-k; i++) {
            tmp = tmp + a[k + i] - a[i];
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }

    return 0;
}

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

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

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

 **********************************************/
#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 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];
                        //cout << "data[i]="<< data[i]<<endl;
                }

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

        return 0;

}

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

int main(){
  int n,k;
  while(cin>>n>>k,n+k!=0){
    long long htoohtoo[n];
    for(int i=0;i<n;i++)
      cin>>htoohtoo[i];
    long long htoo=0;
    long long max=0;
    for(int i=0;i<n-k+1;i++){
      htoo = 0;
      for(int j=0;j<k;j++){
	htoo+=htoohtoo[i+j];
      }
      if(max<htoo){
	max=htoo;
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main()
{
  int n,k;
  int sum,max;
  int i,j;
  vector<int>a;
  while(cin>>n>>k,n|k){
    a.resize(n);
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<n-k;i++){
      sum=0;
      for(j=0;j<k;j++)sum+=a[i+j];
      if(max<sum)max=sum;
    }
    cout<<sum<<endl;
  }
}

C++: #include <iostream>
using namespace std;
int main() {
	while (1) {
		int n, k, a[100005] = { 0 }, m = -9999999999, dp[100005] = { 0 };
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < k; i++) {
			dp[0] += a[i];
		}
		for (int i = 1; i < n - k + 2; i++) {
			dp[i] = dp[i - 1] - a[i - 1] + a[i + k - 1];
		}
		for (int i = 0; i < n - k + 1; i++) {
			//cout << dp[i] << endl;
			if (m < dp[i]) m = dp[i];
		}
		cout << m << endl;
	}
	return 0;
}

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

int n, k;
int a[100000];
int ra[100001];	//ra[i] = a[0] + ??? + a[i-1]

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

		int ans = -1000000001;
		for (int i = k; i <= n; i++) {
			ans = max(ans, ra[i] - ra[i-k]);
		}

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60; //仮想的な無限大の値
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if(N == 0) break;
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        // 累積和を前計算
        vector<int> s(N+1, 0);
        for (int i = 0; i < N; i++) s[i+1] = s[i] + a[i];
        
        // 答えを求める
        long long res = -INF;
        for (int i = 0; i <= N-K; i++) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    int n, k;
    while(1) {
        scanf("%d %d", &n, &k);
        if(n==0 && k==0) break;

        int a[n];
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        int ans, sum;
        ans = -114514;
        for(int i=0; i<n-k+1; i++) {
            sum = 0;
            for(int j=i; j<i+k; j++) {
                sum += a[j];
            }
            ans = max(ans, sum);
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

int main(){
  long long n,k,ans=0;cin>>n>>k;
  long long a[n];for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n-k+1;i++){
    long long temp=0;
    for(int j=i;j<i+k;j++){
      temp+=a[j];
    }
    ans=max(temp,ans);
  }
  cout<<ans<<endl;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
  cin >> n >> k;
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    cin >> set[i];
  }

  for(int i=1;i<n-1;i++){
    if(set[i-1]+set[i]+set[i+1]>max) max=set[i-1]+set[i]+set[i+1];
  }
  cout << max << endl;
  }
}