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() {
  int n, k;
  while (true) {
    cin >> n >> k;
    if (!n && !k) break;
    vector<int> a(n);
    for (int i{}; i < n; ++i) cin >> a[i];

    // 累積和
    vector<ll> s(n + 1, 0);
    for (int i{}; i < n; ++i) {
      s[i + 1] = s[i] + a[i];
    }

    ll ans{numeric_limits<ll>::min()};
    for (int i{}; i <= n - k; ++i) {
      ans = max(ans, s[i + k] - s[i]);
    }

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

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 30;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int B = 320, MAX_N = 100000;

int A[MAX_N], buckets[MAX_N/B];

int sum(int l, int r){
    int res = 0;
    while(l < r && l % B > 0){res += A[l++];}
    while(l < r && r % B > 0){res += A[--r];}
    while(l < r){
        res += buckets[l/B];
        l += B;
    }

    return res;
}

int main(){
    int N, K;
    std::cin >> N >> K;

    REP(i, N){
        std::cin >> A[i];
        buckets[i/B] += A[i];
    }

    int res = -INF;
    REP(i, N){
        if(i+K <= N){
            res = std::max(res, sum(i, i+K));
        }
    }

    std::cout << res << std::endl;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int n, k;
    while (cin >> n >> k, n) {
        vector<long long> ac(n+1, 0);
        for (int i=1; i<=n; ++i) {
            cin >> ac[i];
            ac[i] += ac[i-1];
        }
        long long res = -LLONG_MAX;
        for (int i=k; i<=n; ++i) {
            res = max(res, ac[i] - ac[i-k]);
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<stdlib.h>

using namespace std;

int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;
    if(n == 0) break;
    s = (int*)malloc(sizeof(int) * n);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == n) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
    }

    cout << max << endl;
  }
  return 0;
}

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

/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */

int main()
{
	int n, l;

    while (cin >> n >> l, n || l){
        int a[100000];
        REP(i, n){
            cin >> a[i];
        }

        int sum = 0;
        REP(i, l){
            sum = max(sum, a[i] + a[i + 1] + a[i + 2]);
        }

        CL(sum);
    }

	return (0);
}

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

using namespace std;

int rsw[1000002];

int main() {
	int n, k;
	cin >> n >> k;
	rsw[0] = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		rsw[i + 1] = rsw[i] + a;
	}
	int MAX = rsw[k] - rsw[0];
	for (int i = 0; i < n - k + 1; i++) {
		MAX = max(MAX,rsw[i+k]-rsw[i]);
	}
	cout << MAX << endl;
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)

int N, k, i1, i2;
ll a[100010];

int main() {
    while (cin >> N >> k) {
        if (N == 0) break;
        REP(i,N) cin >> a[i];

        ll S[100010];
        S[0] = 0;
        REP(i,N) {
            S[i+1] = S[i] + a[i];
        }

        int ans = 0;
        REP(i,N+1-k) {
            if (S[i+k] - S[i] > ans) ans = S[i+k] - S[i];
        }

        cout << ans << endl;
    }
}

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

int main(){
  int n,k,data[100000],sum,max;
  while(1){
    cin >> n >> k;
    sum = 0;
    max = -10000000;
    if(n == 0&&k == 0)break;
    for(int i = 0; i < n;i++)
      cin >> data[i];
    for(int i = 0;i < k;i++)
      sum += data[i];
    if(sum > max) max = sum;
    for(int i = 0; i < n-k;i++){
      sum = sum-data[i]+data[i+k];

      if(sum > max)
        max = sum;
    }
    cout << max <<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

LL S[MAX_N+1],n,m;
LL ans;

class BIT{
    public:
        int N;
        void init(int _N){
            N=_N;
            rep(i,N+1)S[i]=0;
        }

        LL getSum(int i){
            LL s=0;
            while(i){
                s+=S[i];
                i-=i&-i;
            }
            return s;
        }

        void add(int i,int x){
            while(i<=N){
                S[i]+=x;
                i+=i&-i;
            }
        }
};

int main(){
    while(1){
        BIT bit;
        int t=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        bit.init(n);
        FOR(i,1,n){
            int x;
            cin>>x;
            bit.add(i,x);
        }
        FOR(i,m,n){
            LL query=bit.getSum(i)-bit.getSum(t);
            ans=max(query,ans);
            t++;
        }
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}

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

int N,K;
int a[100001];

void solve(){
    for(int i=0;i<N;i++){
        scanf("%d",&a[i+1]);
        a[i+1]+=a[i];
    }
    int ma=0;
    for(int i=K;i<=N;i++)ma=max(ma,a[i]-a[i-K]);
    printf("%d\n",ma);
}
int main(){
    while(scanf("%d%d",&N,&K),N||K)solve();
}

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

int data[100000]={0};

int main(){
    int n,k;
    int sum = -1;
    int tmp,tmp2;
    while(1){
        cin >> n >> k;
        if(n == 0 && k == 0) break;
        for(int i=0;i<n;i++) cin >> data[i];
        for(int i=0;i<=(n-k)/2;i++){
            tmp = 0;
            tmp2 = 0;
            for(int j=i,g=n-(i+1);j<i+k;j++,g--){
                tmp += data[j];
                tmp2 += data[g];
            }
            if(sum < tmp) sum = tmp;
            else if(sum < tmp2) sum = tmp2;
        }
        cout << sum << endl;
    }
}

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);
	}
	
	int s, sum = 0;
	for (int i = 0; i < k; i++) sum += inp[i];
	s = sum;
	for (int i = 0; k < inp.size(); i++, k++){
	    s -= inp[i];
	    s += inp[k];
	    if (sum < s) sum = s;
	}
	cout << sum << endl;
    }
}