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;

  int a[101010] = {0};

  cin >> a[1];
  for (int i = 2; i < n + 1; i++){
    cin >> a[i];
      a[i] += a[i - 1];
  }

  int max_n = -1e9;
  for (int i = 0; i < n - k; i++){
    max_n = max(max_n, a[k + i] - a[i]);
  }

  cout << max_n << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,k,box[10000]={0},ans=0,sum=0,summ;
int main(){
    cin >> n >> k;
    for(int i=0;i<k;i++){
            cin >> box[i];
            sum+=box[i];
            }
          for(int i=k;i<n;i++){
                cin >> box[i];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;
return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main(){
	int n,k;
	cin>>n>>k;
	vi a(n);
	REP(i,n){
		cin>>a[i];
	}

	int sum=0;
	REP(i,k){
		sum+=a[i];
	}

	int ans=sum;
	FOR(i,k,n){
		sum+=a[i];
		sum-=a[i-k];
		ans=max(ans,sum);
	}

	cout<<ans<<endl;
}

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

int data[100000]={0};

int main(){
    int n,k;
    int sum = -1;
    int tmp,tmp2,tmp3,tmp4;
    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)/4;i++){
            tmp = 0;
            tmp2 = 0;
            tmp3 = 0;
            tmp4 = 0;
            for(int j=i,g=n-(i+1),f=(n/2)+i,r=(n/2)+i;j<i+k;j++,g--,f++,r--){
                tmp += data[j];
                tmp2 += data[g];
                tmp3 += data[f];
                tmp4 += data[r];
            }
            if(sum < tmp) sum = tmp;
            else if(sum < tmp2) sum = tmp2;
            else if(sum < tmp3) sum = tmp3;
            else if(sum < tmp4) sum = tmp4;
        }
        cout << sum << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m,a[100000],s,ms;
	while(cin >> n >> m,n){
		ms = s = 0;
		for(int i = 0;i < n;++i){
			cin >> a[i];
			if(i < m){
				ms += a[i];
				s += a[i];
			}
			else{
				s = s + a[i] - a[i - m];
				if(ms < s) ms = s;
			}
		}
		cout << ms << endl;
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
int num[100001];
int main(void){
   int n,k;
   while(scanf("%d%d",&n,&k),n+k){
      for(int i = 0;i < n;i++){
         scanf("%d",&num[i]);
      }
      int ma = -200000001;
      for(int i = 0;i <= n-k;i++){
         int part_ma = 0;
         for(int j = i;j < i+k;j++){
            part_ma += num[j];
         }
         if(ma > part_ma) ma = part_ma;
      }
      printf("%d\n",ma);
   }
   return 0;
}

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

#define rep(i, a, b) for(int i = (a); (i) < (b); i++)

using namespace std;

int main() {
	int n, k;
	while(cin >> n >> k, n) {
		vector<int> num;
		int tmp;
		rep(i, 0, n) {
			cin >> tmp;
			num.push_back(tmp);
		}

		int s = 0;
		rep(i, 1, n-k+1) {
			tmp = 0;
			rep(j, 0, k) {
				tmp += num[i+j-1];
			}

			if(s < tmp) s = tmp;
		}
	}

	cout << s << endl;
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

while(1){
    int n, k;
    cin>> n>> k;
    if(n==0&&k==0) break;
    int a[n];
    for(int i=0; i<n; i++){
        cin>> 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=k; i<n; i++){
        sum-=a[k-i];
        sum+=a[i];
        ans=max(ans, sum);
    }

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

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<chrono>
#include<string>
#include<chrono>

using namespace std;






int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	







	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	while (1){
		int n, k;
		cin >> n >> k;
		if (!n and !k) return 0;
		int a[n];
		vector<int> max(n - k);
		REP(i, n) cin >> a[i];
		REP(i, k) max[0] += a[i];
		FOR(i, 1, n-k){
			max[i] = max[i-1] + a[i+k-1] - a[i-1];
		}

		sort(ALL(max), greater<int>());

		cout << max[0] << endl;
	}

}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k; cin >> n >> k;
	vector<LL> sums(n);
	rep(i, n)
	{
		cin >> sums[i];
		if (i != 0)
			sums[i] += sums[i - 1];
	}
	LL ans = -10000000000;
	ans = *max_element(sums.begin(), sums.begin() + k);
	for (int i = 1; i + k < n; i++)
	{
		ans = max(ans, sums[i + k - 1] - sums[i - 1]);
	}
	cout << ans << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

int main()
{
    int n, k, index;
    long a[100005];
    long suma[100005];
    long ans[10];
    index = 0;
    REP(i, 10){
        cin >> n >> k;
        if(n == 0 && k == 0)
            break;
        REP(j, n)
            cin >> a[j];
        suma[0] = 0;
        REP(j, n)
            suma[j+1] = suma[j] + a[j];
        REP(j, n-k+1){
            if(j==0)
                ans[index] = suma[j+k] - suma[j];
            else{
                if(ans[index] < (suma[j+k] - suma[j]))
                    ans[index] = suma[j+k] - suma[j];
            }
        }
        index++;
    }
    REP(i, index)
        cout << ans[i] << endl;

    
    

    return 0;
}