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 num[100005],ans,n,k,sum;
int main(){

    while(1){
    cin >> n >> k;
    if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
            cin >> num[i];
            if(k>i)sum+=num[i];
    }


    for(int i=k;i<n;i++){
        ans=max(ans,sum);
        //cout << "#" << sum << endl;
        sum-=num[i-k];
        sum+=num[i];
    }

    cout << ans << endl;
    }

return 0;
}

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

using namespace std;

int main() {
  while (true) {
    int n,k;
    cin >> n >> k;
    if(n == 0 && k == 0)
      return 0;

    int sum[n+1];
    sum[0] = 0;

    for (int i = 0; i < n; i++){
      int s;
      cin >> s;
      sum[i+1] = sum[i] + s;
    }

    int ans = -1987654321;

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

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

C++: #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)	return 0;
		int a[n];
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);;
		ll bgs=0;
		for(int i=0;i<=n-k;i++){
			ll temp=0;
			for(int j=0;j<k;j++)	temp+=a[i+j];
			bgs=max(bgs,temp);
		}
		printf("%lld\n",bgs);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    vector<int> ans(0);x
    while(1){
        cin>>n>>k;
        if(n==0&&k==0){
            break;
        }
        vector<int> vec(n);
        for(int i=0;i<n;i++){
            cin>>vec.at(i);
        }
        vector<int> rsw(n+1);
        rsw.at(0)=0;
        for(int i=1;i<n+1;i++){
            rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
        }
        ans.push_back(0);
        for(int i=k;i<n+1;i++){
            if(ans.at(ans.size()) < rsw.at(i) - rsw.at(i-k)){
                ans.at(ans.size()) = rsw.at(i) - rsw.at(i-k);
            }
        }
        cout << ans.at(ans.size()) << endl;
    }
    
}

C++: #include<cstdio>

int N,K;
int a[100000];


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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int N, K;
    while(cin >> N >> K) {
        if(N == 0) break;
        vector<ll> 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];

        ll res = -INF;
        for(int i = 0; i <= N-K; ++i) {
            ll val = s[K+i] - s[i];
            if(res < val) res = val;
        }
        cout << res << endl;
    }

}

C++: #include<stdio.h>
#include <iostream>
int length;
int k;
int* a;
//int sum;
int main(){
  while(1){
  std::cin>>length;
  std::cin>>k;
    if(k==0&&length==0)return 0;
  a=new int[length];
  for(int i=0;i<length;i++){
    int input=0;
    std::cin>>input;
    a[i]=input;
  }
  int* sums=new int[length];
  int s=0;
  for(int i=0;i<length;i++){
    s+=a[i];
    sums[i]=s;
  }
    //std::cout<<"\n";
  int max=0;
  int psum=0;
    int idx=0;
  for(int i=0;i<length-k;i++){
    int diff=sums[i+k]-sums[i];
    if(diff>max){
      max=diff;
      idx=i;
      
    //std::cout<<"\n";
    }
      //std::cout<<diff;
  }
  std::cout<<std::to_string(max)+"\n";
  //std::cout<<std::to_string(idx)+"\n";
  //std::cout<<s;
  }
  return 0;
}

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

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)

const int INF = 1 << 24;

typedef unsigned long long ull;

const int MAX_N = 1 << 18;

class SegmentTree{
public:
    SegmentTree(int n){
        size = 1;
        while(size < n){
            size *= 2;
        }

        REP(i, 2*n-1){
            data[i] = 0;
        }
    }

    void push(int k, int v){
        k += size - 1;
        data[k] = v;

        while(k > 0){
            int parent = (k - 1) / 2,
                c1 = parent * 2 + 1, c2 = parent * 2 + 2;

            data[parent] = data[c1] + data[c2];
            k = parent;
        }
    }

    int query(int l, int r){
        return _query(l, r, 0, 0, size);
    }

    int _query(int l, int r, int k, int a, int b){
        if(r <= a || b <= l){return 0;}

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

private:
    int data[MAX_N], size;
};

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

        REP(i, N){
            int n;
            std::cin >> n;

            st.push(i, n);
        }

        int res = 0;
        REP(i, N){
            if(i + K <= N){
                res = std::max(res, st.query(i, i+K));
            }
        }

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

C++: #include<stdio.h>
int main(void)
{
	int n,k,max=0,s,i,j,a[100001];
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0) break;
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
		for(i=1;i<=n;i++){
			s=0;
			if(i+k<=n){
				for(j=i;j<i+k;j++) s+=a[j];
				if(max<s) max=s;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n, m, s[10000000], k[10000000], MAX;
int main() {
	while (true) {
		MAX = -2000000000;
		cin >> n >> m;
		if (!n) { break; }
		for (int i = 1; i <= n; i++) {
			cin >> s[i];
			k[i] = k[i - 1] + s[i];
		}
		for (int i = 1; i <= n - m; i++) {
			MAX = max(MAX, k[i + m] - k[i]);
		}
		cout << MAX << endl;
	}
}

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

using namespace std;

typedef long long ll;

int a[1000000];

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;
    }
}