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()
{
	int n, k, i, j, inp, max=0;
	int *a;
	cin >> n >> k;
	a = new int[n];
	
	for (i = 0; i < n; i++){
		cin >> inp;
		a[i] = inp;
	}
	
	int o1, o2;
	cin >> o1 >> o2;

	for (i = 0; i < n - k + 1; i++){
		int sum = 0;

		for (j = 0; j < k; j++){
			sum += a[i + j];
		}

		if (sum > max){ max = sum; }
	}

	cout << max << endl;

	delete[] a; 
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define LINF 1LL << 60

int main(){
  int n, k;
  while(cin >> n >> k && n != 0){
    vector<ll> a(n);
    vector<ll> sum(n + 1, 0);
    for(int i = 0; i < n; ++i){
      cin >> a[i];
      sum[i + 1] = sum[i] + a[i];
    }

    ll ans = -LINF;
    for(int i = 0; k + i <= n; ++i){
      ll tmp = sum[k + i] - sum[i];
      if(tmp > ans)ans = tmp;
    }

    cout << ans << endl;
  }
}

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

int main(){
	int n,k;

	while(true){
		int max=0,s=0;
		vector<int> a;

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

		for(int i=0;i<n;i++){
			int t;
			cin>>t;
			a.push_back(t);
		}
		
		for(int i=0;i<k;i++){
			s+=a[i];
		}

		max=s;

		for(int i=1;i<=n-k;i++){
			int t=i+k-1;
			s=s-a[i-1]+a[t];
			if(max<s) max=s;
		}

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

C++: #include<iostream>

const int MAX_N = 1 << 18, INF = 1 << 24;

class SegmentTree{
public:
	SegmentTree(int _n){
		n = 1;
		while(n < _n)n *= 2;
		for(int i=0;i<2*n-1;i++){
			data[i] = 0;
		}
	}

	void add(int k, int a){
		k += n - 1;
		data[k] = a;
		while(k > 0){
			k = (k-1) / 2;
			data[k] = data[k*2+1] + data[k*2+2];
		}
	}

	int calculate(int a, int b){
		return _calculate(a, b, 0, 0, n);
	}
private:
	int data[MAX_N];
	int n;
	int _calculate(int a, int b, int k, int l, int r){
		if(r <= a || b <= l)return 0;

		if(a <= l && r <= b)return data[k];
		else{
			int l_child = _calculate(a, b, 2*k+1, l, (l+r) / 2),
				r_child = _calculate(a, b, 2*k+2, (l+r) / 2, r);
			return l_child + r_child;
		}
	}
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		SegmentTree st(n);
		for(int i=0;i<n;i++){
			int a_i;
			std::cin >> a_i;
			st.add(i, a_i);
		}

		int res = -INF;

		for(int i=0;i+k-1<n;i++){
			res = std::max(res, st.calculate(i, i+k));
		}

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

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

using namespace std;

int a[100100];
int main(){

while(1){
    int n, k;
    cin>> n>> k;
    if(n==0&&k==0) break;
    for(int i=0; i<n; i++){
        scanf("%d", &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 <iostream>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < n; i++)



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<long long int> num(n);
        rep(i, n) std::cin >> num.at(i);

        long long int sum = std::accumulate(num.begin(),num.begin()+k,0LL);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,n2[100001],n_sum[100001];
    while(1){
    cin>>n>>k;
    if(n==0&&k==0)return 0;
    for(int i=0;i<n;i++){
        cin>>n2[i];
    }
    n_sum[0]=0;
    for(int i=1;i<=n;i++){
        n_sum[i]=n_sum[i-1]+n2[i-1];
    }
    int maxx=-10000001;
    for(int i=k-1;i<n;i++){
        int sum=0;
        sum=n_sum[i]-n_sum[i-k];
       // cout<<sum<<endl;
        maxx=max(maxx,sum);
    }
    cout<<maxx<<endl;
    }
}

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

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++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0516
#include <iostream>
#include <algorithm>
#include <vector>
#define INF (1<<30)
#define ll long long
using namespace std; 
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (true) {
		ll n, k; cin >> n >> k;
		if (n == 0 && k == 0)break;
		vector<ll> Sum(n + 1);
		Sum[0] = 0;
		for (int i = 1; i <= n;i++) {
			ll N; cin >> N;
			Sum[i] = Sum[i - 1] + N;
		}
		ll ans = -INF;
		for (int i = 1; i <= n - k + 1;i++) {
			ans = max(ans, Sum[i+k-1] - Sum[i - 1]);
		}
		cout << ans << endl;
	}

}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    for(int count = 0;  count < 5; count++){
	    int none(2);
	    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 < k) total += a[i];
		else total = total + a[i] - a[i-k];
		if(ans < total) ans = total;
	    }
	    cout << ans << endl;
	    cin >> none.at(0) >> none.at(1);
　　}
}

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

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

    int* num_sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
      cin >> num_sequence[i];
    }

    max = -999999;
    int m = n-k+1;
    for (int j = 0; j < m; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    delete[] num_sequence;
  }
  return 0;
}

C++: #include <cstdio>

int main() {
    long n, k;
    for (;;) {
        long a[100002] = {};
        scanf("%ld %ld", &n, &k);
        if (n == 0)
            return 0;
        for (long i = 0; i < n; i++) {
            scanf(" %ld", &a[i]);
        }
        long max = -2147483648;
        for (long i = 0; i < n - k; i++) {
            long result = a[i] + a[i+1] + a[i+2];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


int main(){
    
    int n,k;
    cin>>n>>k;
    vector<ll> a(n);
    REP(i,n)cin>>a[i];
    
    ll sum=0;
    REP(i,k)sum+=a[i];
    
    ll ans=sum;
    for(int i=k;i<n;i++){
        sum-=a[i-k];
        sum+=a[i];
        ans=max(ans,sum);
    }
    
    cout<<ans<<endl;
    
    return 0;
}