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 <stdlib.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	vector<int> results;

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

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

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

			if (max < s) {
				max = s;
			}
		}

		results.push_back(max);
	}

	for (int i = 0; i < results.size(); i++)
		cout << results[i] << endl;

	return 0;
}

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

long long int sum,k,n,num[200000];

int main(){

    while(1){

    long long int ans=-100000000000;
    cin >> n >> k;
    if(n==0&&k==0)break;

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

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

    }

    cout << ans << endl;
    }


return 0;
}

C++: #include <vector>
#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>

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 EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#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)

const double EPS = 1e-10;

int main() {
	int n, k;
	ll result, tmp;

	cin >> n >> k;

	vi nums(n);
	result = -INT_MAX;
	tmp = 0;

	REP(i, n) {
		cin >> nums[i];
	}

	REP(i, n-k) {
		REP(j, k) {
			tmp += nums[i+j];
		}

		if(result < tmp) {
			result = tmp;
		}
	}

	cout << result << endl;

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
  int n,k;
  int a[100005];
  ll ans,sum;
  while(cin>>n>>k){
    if(n==0&&k==0)break;
    ans=0;
    rep(i,n)cin>>a[i];
    rep(i,k)ans+=a[i];
    sum=ans;
    REP(i,k,n){
      sum=sum-a[i-k]+a[i];
      ans=max(sum,ans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int num[100000];

int main() {
	while(1){
		int n, k;
		cin >> n >> k;
		if(n == 0 && k == 0)break;
		
		int sum = 0;
		for(int i = 0; i < k; i++){
			cin >> num[i];
			sum += num[i];
		}
			
		int ans = 0;
		for(int i = k; i < n; i++){
			cin >> num[i];
			sum -= num[i - k];
			sum += num[i];
			if(ans < sum)
				ans = sum;
		}
		
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int n,k;
    while (cin >> n >> k) 
    {
        if (n == 0 && k==0) 
        {
            break;
        }
        vector<int> vec(n);
        int sum=0;
        int sum_max=0;
        for (int i = 0; i < n-k +1; i++) 
        {
            cin >> vec[i];
            if (k - 1 < i) 
            {
                for (int j = 0; j < k; j++) 
                {
                    sum += vec[i + j];
                }
                sum_max = max(sum ,sum_max);
            }
        }
        cout << sum_max << endl;
    }
    return 0;
}

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

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

int main(){

	int n,k,s,data;
	s = 0;
	
	while(cin >> n,n){
	cin >> k;
	vector<int> sum;	

	rep(i,n){
		cin >> data;
		sum.push_back(data);
	}
	
	rep(i,k){
		data = 0;
		rep(j,k){	
			if(i+j < n) data += sum[i+j];
		}
		if(s < data) s = data;	
	}

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

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;

int main()
{
	while (1)
	{
		int a = 0, b = 0;
		double c = -1000;
		cin >> a;
		cin >> b;
		if (a == 0 && b == 0)
		{
			break;
		}
		vector<double> size;
		for (int i = 0; i < a; i++)
		{
			int w;
			cin >> w;
			size.push_back(w);
		}
		for (int i = 0; i < a - 2; i++)
		{
			double as = 0;
			for (int ii = 0; ii < b; ii++)
			{
				as += size[i + ii];
			}
			size.push_back(as);
		}
		for (int i = 0; i < a - 2; i++)
		{
			if (c < size[i + a])
			{
				c = size[i + a];
			}
		}
		cout << c << endl;
	}	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int num[1000000];
int main()
{
	int n, k, ans = 0, anss = 0;
	while (1)
	{
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0)
			break;
		num[0] = 0;
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &num[i]);
			num[i] = num[i] + num[i - 1];
		}
		for (int i = k; i <=n; i++)
		{
			anss = num[i] - num[i - k];
			if (ans < anss)
				ans = anss;
		}
		printf("%d\n", ans);
	}
	return 0;
}