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;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < 3){
    	    total += a[i];
    	}else{
    	    total = total + a[i] - a[i-3];
    	}
	    if(ans < total){
	        ans = total;
	    }
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    while(cin >> n >> k, n | k)
    {
        vector<int> A(n);
        for(int i = 0; i < n; i++) cin >> A[i];
        vector<int> sum(n + 1, 0);
        for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + A[i - 1];
        int ans = -1;
        for(int i = 1; i <= n - k; i++)
        {
            ans = max(ans, sum[i + k] - sum[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

int a[10000];

int main()
{
    int n, k;
    while(cin >> n >> k && n && k) {
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        ll pre = 0;
        for(int i = 0; i < k; i++) {
            pre += a[i];
        }
        
        ll ret = pre;
        for(int i = 0; i < n - k; i++) {
            pre = pre - a[i] + a[k + i];
            ret = max(ret, pre);
        }
        
        cout << ret << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int n,k;
int A[100001];
int main(){
  while(1){
    scanf("%d %d",&n,&k);
    if(!n && !k) break;
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    int res=0;
    int sum=0;
    for(int i=0;i<k;i++){
      sum+=A[i];
    }
    res = sum;
    for(int i=k,j=0;i<n;i++,j++){
      sum-=A[j]; sum+=A[i];
      res = max(res,sum);
    }
    printf("%d\n",res);
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

signed main()
{
    int n, k; cin >> n >> k;
    static int a[100010], sum[100010];
    rep(i, n) cin >> a[i];

    for (int i = 0; i < n; ++i) sum[i + 1] = a[i] + sum[i];

    int ma = -1e9;

    rep(i, n - k + 1) {
        ma = max(ma, sum[i + k] - sum[i]);
    }

    cout << ma << endl;
}

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

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[100000];
	for(int i=0;i<100000;i++) wa[i] = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		for(int j=0;j<k;j++){
			wa[i+j] += x;
		}
	}
	cin >> x >> x;
	for(int i=k-1;i<n;i++){
		if(maxnum < wa[i]) maxnum = wa[i];
	}
	cout << maxnum;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	int K;
	cin>>K;
	vll v(n);
	rep(i,n) cin>>v[i];
	ll cnt=0;
	ll ans=-INFL;
	ll sum=0;
	rep(i,n){
		if(cnt<K){
			sum+=v[i];
		}
		else{
			sum+=v[i]-v[i-K];
		}
		maxs(ans,sum);
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int a[100000],n,k,s,ans;
int main(){
	while(true){
	cin>>n>>k;
	if(!n&&!k)break;
	s=0,ans;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i<k)s+=a[i];
	}
	ans=s;
	for(int i=k;i<n;i++)s+=a[i]-a[i-k],ans=max(s,ans);
	cout<<ans<<endl;
	}
	return 0;
}

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



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

                max=0;
                temp=0;
                for(int i=0; i+k<=n; i++) {
                        temp=v[i+k]-v[i];
                        if(temp>max) max=temp; //tempが最も大きい数値ならmaxを更新
                        temp=0; //tempの初帰化
                }
                cout<<max<<endl;
        }
}

C++: #include<iostream>
using namespace std;
int n2[100001];
int main() {
	int n, k;
	int cnt = 0, cnt_max = -10001;
	while (1) {
		cin >> n >> k;
		if (n == 0 && k == 0)return 0;
		for (int i = 1; i <= n; i++) {
			cin >> n2[i];
		}
		for (int i = 1; i <= n - k + 1; i++) {
			cnt = n2[i];
			for (int j = 1; j < k; j++) {
				cnt += n2[i + j];
			}
			if (cnt_max < cnt) {
				cnt_max = cnt;
			}
		}
		cout << cnt_max << endl;
		cnt_max = 0;
	}
}