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;
typedef long long int ll;
int main(){
	int n, k;
	int a[100000];
	for(;;){
		cin >> n >> k;
		if(n == 0 && k == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		ll ans = 0;
		for(int i = 0; i < k; i++){
			ans += a[i];
		}
		ll sum = ans;
		for(int i = k; i < n; i++){
			sum -= a[i - k];
			sum += a[i];
			if(sum > ans) ans = sum;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	while(1){
        int n,k;
        int ans[10010] = {0};
        cin >> n >> k;
        if(n + k == 0) break;
        for(int i = 0; i < n; i++){
            cin >> ans[i];
        }
        int mx = 0,sum = 0;
        for(int i = 0; i < k; i++){
            sum += ans[i];
        }
        mx = sum;
        for(int i = k; i < n; i++){
            sum += ans[i];
            sum -= ans[i-k];
            mx = max(mx,sum);
        }
        cout << mx << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 10000

int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%d %d", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%d", &a[i]);
    for(i = 0; i < n - k; i++){
      f = 0;
      for(j = 0; j < k; j++) f += a[i + j];
      if(f > max) max = f;
    }
    printf("%d\n", max);
  }
  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[100001] = {};

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

 
  int maxsum = 0;
  int sum;
  for(int i=0;i<k;i++) maxsum += a[i];

  sum = maxsum;
  for(int i=k;i<n;i++) {
    sum =sum + a[i] - a[i-k];
      if(sum > maxsum) maxsum = sum;
  }

  cout << maxsum <<endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

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

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

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t >= s) {
        s = t;
      }
    }
    cout << s << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
long long n, k, a[200000], s, ret;
int main() {
	while (true) {
		cin >> n >> k; s = 0; if (n == 0)break; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (i <= k)s += a[i]; }
		ret = s; for (int i = k + 1; i <= n; i++) { s -= a[i - k]; s += a[i]; ret = max(ret, s); }
		cout << ret << endl;
	}
	return 0;
}

C++: #include<iostream>
main(){
  for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))
    for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<i)*a[i++ -k],k<i&&M<s&(M=s))std::cin>>a[i];
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	int box[100001];
	int sum;
	int MAX;
	int i;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)	break;
		sum=0;	
		for(i=0;i<n;i++)	cin>>box[i];
		for(i=0;i<m;i++)	sum+=box[i];
		MAX=sum;
		for(i=m-1;i<n-1;i++){
			// cout<<sum<<" "<<box[i+1]<<" "<<box[i-2]<<endl;
			sum=sum+box[i+1]-box[i-(m-1)];
			// cout<<sum<<endl;
			MAX=max(MAX,sum);
		}
		cout<<MAX<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n, k;
	int n2[5001];
	int cnt = 0, cnt_max = -10001;
	while (1) {
		cin >> n >> k;
		if (n == 0 && k == 0)return 0;
		for (int i = 1; i <= n; i++) {
			cin >> n2[i];
		}
		for (int i = 1; i <= n - k + 1; i++) {
			cnt = n2[i];
			for (int j = 1; j < k; j++) {
				cnt += n2[i + j];
			}
			if (cnt_max < cnt) {
				cnt_max = cnt;
			}
		}
		cout << cnt_max << endl;
		cnt_max = 0;
	}
}

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

constexpr int MAX_N= 100000;

int n,k,sum;
int a[MAX_N];
int ans;

int main(){
    while(1){
    	std::cin>>n>>k;
    	if(n+k==0)
    		break;
    	sum=0;
    	ans=0;
    	for(int i=0;i<n;++i)
    		std::cin>>a[i];

    	for(int i=0;i<k;++i)
    		sum+=a[i];

    	for(int i=0;i<n-k;++i){
    		ans=std::max(ans,sum-a[i]+a[i+k]);
    	}

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

C++: #include <iostream>
using namespace std;
int main(void){
	for (;;){
		int a,b,c,d,max=0,m;
		cin>>a>>b;
		int e[a]={0};
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>e[c];
		}
		m=a-b;
		for (c=0;c<a-m;c++){
			for (int y=1;y<b;y++) e[c]=e[c]+e[c+y];
			if (max<e[c]) max=e[c];
	}
		cout<<max<<endl;
	}
	return 0;
}

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[0] >> none[1];
　　}
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;
const long long INF = 1LL<<60; // 仮想的な無限大の値
vector<bool> seen;

Graph G;

int solve(ll a,ll b,ll c){

    for(int i=0;i < 1000;i++){

        if(a & 1) return i;
        if(b & 1) return i;
        if(c & 1) return i;

        ll ta,tb,tc;
        ta = (b + c)/2;
        tb = (a + c)/2;
        tc = (a + b)/2;

        a = ta;
        b = tb;
        c = tc;

    }
    return -1;
}


int main() {

    //累積和
    //区間kで長さを与えた時の累積わの最大値
    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;
        ll val;

        for(int i=0;i + k <= n;i++ ){
            val = s[i + k] - s[i];
            if(res < val) res = val;
        }
        cout << res << endl;


    }
    


    return 0;

}

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

int main()
{
	while (1)
	{
		int a = 0, b = 0;
		double c = -1000;
		double as = 0;
		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++)
		{
			
			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 <bits/stdc++.h>
using namespace std;

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;

    if (n == 0 && k == 0) {
      break;
    }

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

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

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

    cout << ans << endl;
  }
}