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;

constexpr int MAX_N = 1e5;
int a[MAX_N];

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

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

    // 累積和
    vector<int> s(n + 1, 0);
    for (int i{}; i < n; ++i) {
      s[i + 1] = s[i] + a[i];
    }

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

    cout << ans << endl;
  }

  return 0;
}

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

int main(){
  int n,k;
  long long int ans=-1000000000;
while(true){
  std::cin>>n>>k;
if(n==0&&k==0)break;
  std::vector<long long int>vec(n+1,0);
  long long int sub;
  for(int i=1;i<=n;i++){
    std::cin>>sub;
    vec.at(i)=vec.at(i-1)+sub;
  }
  for(int i=n;i>=k;i--){
    ans=std::max(vec.at(i)-vec.at(i-k),ans);
  }
  std::cout<<ans<<std::endl;
}
  return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=-1000000000,sum;
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
}

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 <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>

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);
        vector<int> sum(n -k +1);
        int input;
        for (int i = 0; i < n; i++) 
        {
            cin >> vec[i];//input;
            //vec.push_back(input);
        }
        for (int i = 0; i < n - k + 1; i++) 
        {
            sum[i]=0;
            for (int j = 0; j < k; j++) 
            {
                sum[i] += vec[i + j];
                //cout << " " << vec[i+j] << endl;
            }
            //cout << "sum="<< sum[i] << endl;
        }
        //for (int i = 0; i < n-k+1; i++) 
        //{
        //    cout << vec[i]<<endl;
        //}
        sort(sum.begin(), sum.end() , greater<int>() );
        //for (int i = 0; i < n-k+1; i++) 
        //{
        //    cout << vec[i]<<endl;
        //}
        cout << sum[0];
    }
    return 0;
}

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

int main(){
  int n;
  int k;
  int temp;

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

    for(int i=0;i<n;++i){
      cin>>temp;
      data.push_back(temp);
    }
    
    for(int i=0;i<n-k+1;++i){
      int total=0;
      for(int j=i;j<k+i;++j){
	total+=data[j];
      }
      if(max<total)
	max=total;
    }
    cout<<max<<endl;
  }
}

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

template<typename T>
class CumulativeSum{
public:
  
  int n;
  vector<T> A, S;
  
  CumulativeSum(){ assert( false && "引数がありません" ); };
  CumulativeSum(vector<T> Array) : A(Array) { n = (int)A.size(); apply(); };
  
  // 初期値からAに変更があった場合、この関数を使うまでSが更新されないことに注意
  void apply(){
    S = vector<T>( n + 1 );
    for(int i=1;i<=n;i++) S[i] = S[i-1] + A[i-1];
  }
  
  // 0 origin
  void update(int k, T v){ A[k] = v; }
  
  // 0 origin, [ begin, end )
  T get(int begin, int end){ return S[end] - S[begin]; }
  
};

signed main(){
  
  int n, k;

  while(1){
    
    vector<int> A;

    cin >> n >> k;
    
    if( !n && !k ) break;
    
    for(int i=0;i<n;i++){
      int a;
      cin >> a;
      A.push_back( a );
    }
  
    CumulativeSum<int> C( A );
    
    int ans = -1e10;
    
    for(int i=0;i<n;i++){
      if( n <= i + k ) break;
      ans = max( ans, C.get( i, i + k ) );
    }

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int;

int main() {

	int n, k;
	while (cin >> n >> k, n ) {
		vector <ll> a(n);
		for (int i = 0; i < n; i++)cin >> a[i];

		vector<ll> s(n + 1, 0);
		for (int i = 0; i < n; i++) {
			s[i + 1] = s[i]+a[i];
		}

		ll res = -100000000001;

		for (int i = 0; i <= n - k ; i++) {
			ll sum = s[i + k] - s[i];
			res = max(res, sum);
			
		}
		cout << res << endl;
	}


	return 0;
}

C++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
while(1)
{
	int n,k;
	scanf("%d %d",&n,&k);
	if(!n) return 0;
	int ret=-INF;
	int res=0;
	queue<int>que;
	for(int i=0;i<k;i++)
	{
		int s; scanf("%d",&s);
		res+=s;
		que.push(s);
	}
	ret=max(ret,res);
	for(int i=k;i<n;i++)
	{
		int s; scanf("%d",&s);
		res+=s;
		res-=(que.front());
		ret=max(ret,res);
		que.pop();
		que.push(s);
	}
	printf("%d\n",ret);
}
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int n,a[100001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
for(i=1;i<=n;i++){
a[i]=0;
}
while(1){
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;j<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=1;i<=n;i++){
a[i]=0;
}
cin>>a[1];
}
return 0;
}

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

#define MAX_N 100010
int N, K;
int S[MAX_N];

int main() {
  while (true) {
  cin >> N >> K;
  if (N == 0 && K == 0) break;
  int ans = INT_MIN;
  for (int i=0; i<N; i++) cin >> S[i];

  for (int i=0; i<=N-K; i++) {
    int t = 0;
    for (int j=0; j<K; j++) t += S[i+j];
    ans = max(ans, t);
  }
  cout << ans << "\n";
  }
  return 0;
}

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

using namespace std;

int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * n);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == n) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
    }

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

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

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[100000];
	for(int i=0;i<100000;i++) wa[i] = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		for(int j=0;j<k;j++){
			wa[i+j] += x;
		}
	}
	cin >> x >> x;
	for(int i=k-2;i<n;i++){
		if(maxnum < wa[i]) maxnum = wa[i];
	}
	cout << maxnum;
}