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>
using namespace std;
int main(){
	while (true){
		int n, k;
		double a[100001] = {}, b[100001] = {}, ans;
		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[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: // #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------


int main(){
  ll N,K;
  cin >> N >> K;
  while(1){
    if(N==0 && K==0){
      break;
    }
    vector<ll> a(N);
    for(int i=0; i<N; i++){
      cin >> a[i];
    }
    vector<ll> S(N+1,0);
    for(int i=1; i<N; i++){
      S[i+1] = S[i] + a[i];
    }
    ll ans=0;
    for(int i=K; i<=N; i++){
      chmax(ans, S[i]-S[i-K]);
    }
    cout << ans << endl;
    cin >> N >> K;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int INF = 1001001001;

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

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

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

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

 **********************************************/
#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;
                //cout << "n=" << n << "k=" << k << endl;
                if(n==0 && k==0)break;
                
                for(int i=0; i<n; i++){
                        cin >> data[i];
                }
               

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

                cout << answer << endl;
                
        }

        return 0;

}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



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

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



int main(){
        int n, k,max,temp,num;
        while(true) {  //ベクターに格納
                cin >> n>>k;
                if(n==k==0) break;
                vector<double> v;
                for(int i=0;i<n;i++){
                  cin>>num; //入力をnumに代入
                  v.push_back(num); //ベクターvにプッシュ
                }

                max=0;
                temp=0;
                for(int i=0; (i+k)<=n; i++) {
                        for(int j=0; j<k; j++) {
                                temp+=v[i+j]; //tempにvのiからi+k番目までの総和を代入
                        }
                        //cout<<temp<<endl;
                        if(temp>max) max=temp; //tempが最も大きい数値ならmaxを更新
                        temp=0; //tempの初帰化
                }
                cout<<max<<endl;
        }
}

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

int main() {
    using namespace std;
    
    int n, k;
    while(cin >> n >> k, (n|k)) {
        int arr[n]; cin >> arr[0]; for(int i=1; i<n; i++) { cin >> arr[i]; arr[i] += arr[i-1]; }
    
        int res = INT_MIN/4;

        for(int i=0; i<n-k; i++) {
            res = max(res, arr[i+k]-arr[i]);    
        }
    
        cout << res << endl;
    }
    
    return 0;
}

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

int a[200000];
int n,l,s,maxn;;

int main(){
    while(true){
        cin>>n>>l;
        if(n==0 && l==0){break;}
        for(int i=0;i<n;i++){
            cin>>a[i];
            if(i<l){s+=a[i];}
        }
        maxn=s;
        for(int i=0;i<n-l;i++){
            s-=a[i];
            s+=a[i+l];
            maxn=max(s,maxn);
        }
        cout<<maxn<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int num[100100];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<100100;i++)num[i]=0;
         cin>>n>>m;
         if(n==0&&m==0)break;
         for(int i=0;i<n;i++) cin>>num[i];
         for(int i=0;i<n-m;i++){
              int min=num[i]+num[i+1]+num[i+2];
              if(ans<min)ans=min;
         }
         cout<<ans<<endl;
         ans=0;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  while(n!=0|k!=0){
    int max=0,ans,i;
    int a[n];
    for(i = 0;i < n;i++){
      scanf("%d",&a[i]);
      if(i < k){
	max += a[i];
	ans = max;
      }
      else {
	max = max + (a[i] - a[i-k]);
	if(ans < max) ans = max;
      }
    }
    printf("%d\n",ans);
    cin >> n >> k;
  }
  return (0);
}