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 <cstdio>
#include <cstring>
#define max(a,b) ((a)>=(b)?(a):(b))
int BIT[100001],n,k;
int sum(int i) {
	int s=0;
	while(i>0) {
		s+=BIT[i];
		i-=i&-i;
	}
	return s;
}
void add(int i,int x) {
	while(i<=n) {
		BIT[i]+=x;
		i+=i&-i;
	}
}
int main() {
	while(scanf("%d %d",&n,&k),n|k) {
		memset(BIT,0,sizeof(BIT));
		for(int i=1;i<=n;i++) {
			int a;
			scanf("%d",&a);
			add(i,a);
		}
		int mx=-1000000000;
		for(int i=1;i<=(n-k+1);i++) {
			mx=max(mx,sum(i+k-1)-sum(i-1));
		}
		printf("%d\n",mx);
	}
}

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

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

int main(){
  long long n,k,ans=-1000000000;cin>>n>>k;
  long long a[n];for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n-k+1;i++){
    long long temp=0;
    for(int j=i;j<i+k;j++){
      temp+=a[j];
    }
    ans=max(temp,ans);
  }
  cout<<ans<<endl;
}

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

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

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<k;i++){
        sum+=num[i];
    }

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

    cout << ans << endl;

    sum=0;
    ans=0;

    }


return 0;
}

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

using namespace std;

int n,m,cnt;
int ans,an;
int a[100000];

int main(void){

  while( cin >> n >> m , n || m ){

    ans = 0;

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

    for( int i = 0 ; i < n - m ; i++ ){
      an = 0;
      cnt = 3;
      for( int j = i ; j < i + 3 ; j++ ){
	an += a[j];
      }
      ans = max( ans , an );
    }

    cout << ans << endl;

  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <numeric>
using namespace std;
int main(){
  int n, k;
  int N[100001], ans, sum;
  while(cin >> n >> k, n && k){
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }
    for(int i = 0 ; i < n - k ; i++){
      sum = 0;
      sum = accumulate(N+i, N+i+k, 0);

      /*for(int j = i ; j < k + i ; j++){
	sum += N[j];
	}*/
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int n, k;
	int a[100000];
	int sum = 0;
	int Max = 0;
	
	while(true){
		cin >> n >> k;
		if(n + k == 0){
			for(int i = 0; i < n; i++){
			cin >> a[i];
		}
	
		for(int i = 0; i < n-k+1; i++){
			sum = 0;
			for(int j = i; j < i+k; j++){
				sum += a[j];
			}
			Max = max(Max, sum);
		}
	
		cout << Max << 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(i=s=0;i<n;s+=a[i++],k<i&&(s-=a[i-k-1]),M<s&&(M=s))std::cin>>a[i];}

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

int data[100000]={0};

int main(){
    int n,k;
    int sum = -1;
    int tmp;
    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;i++){
            tmp = 0;
            for(int j=i;j<i+k;j++) tmp += data[j];
            if(sum < tmp) sum = tmp;
        }
        cout << sum << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n,k;
int a[100000];
int sum[100000];

void solve() {
  sum[0] = a[0];
  for(int i=1;i<n;i++) {
    sum[i] = sum[i-1] + a[i];
  }
  int res = sum[k-1];
  for(int i=0;i<=n-k;i++) {
    res = max(res,sum[i+k-1] - sum[i-1]);
  }
  cout << res << endl;
}

int main() {
  while(cin >> n >> k) {
    if(n==0 && k==0) break;
    for(int i=0;i<n;i++) {
      cin >> a[i];
    }
    solve();
  }
}

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

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) return 0;
    
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    
    int sum, max;
    int head = k - 1, tail = 0;
    sum = 0;
    for (int i = tail; i <= head; i++) {
      sum += a[i];
    }
    max = sum;
    
    while (head < n - 1) {
      sum -= a[tail++];
      sum += a[++head];
      if (sum > max) max = sum;
    }
    cout << max << endl;
  }
}

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

int sum(int S[], int begin, int end) {
    int ans = 0;
    for (int i = begin; i < end; ++i) {
        ans += S[i];
    }
    return ans;
}

int main() {

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

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

        int m = n - k + 1;
        int tmp = 0;
        int ans = -1000000000;
        for (int i = 0; i < m; ++i) {
            int tmp = sum(S, i, i + k);
            if (ans < tmp) ans = tmp;
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n,k;
	while(cin>>n>>k && n && k){
		int s[200000];
		s[0]=0;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			s[i]=s[i-1]+x;
		}
		int ans=s[k];
		for(int i=0;i+k<=n;i++){
			ans=max(ans,s[i+k]-s[i]);
		}
		cout<<ans<<endl;
	}
}

C++: /**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@16:28

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){
                
                int n=0;
                int k=0;
                int all=0;
                int total=0, answer=0;
                vector<int> data(5000);

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

                for(int j=0; j<n-k; j++){
                        
                        if( j == 0){
                                for(int i=0; i<k; i++){
                                        total = total + data[j+i];
                                }
                        }else{
                                
                                total = total - data[j-1] + data[j+k-1];
                        }
                        
                        if( answer < total){
                                answer = total;
                        }
                        
                }
                
                cout << answer << endl;
                
        }

        return 0;

}

C++: #include <iostream>

int kk[100000];

int main(){

int s=0;
int n,k;
std::cin>>n>>k;

for(int i=0;i<k;i++){
std::cin>>kk[i];
s+=kk[i];
}

int st=s;

for(int i=k;i<n;i++){
std::cin>>kk[i];
s+=kk[i]-kk[i-k];
if(s>st)
st=s;
}

std::cout<<st<<std::endl;

}